• Post Reply Bookmark Topic Watch Topic
  • New Topic

Simple job scheduling for a servlet app  RSS feed

 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks,
I'm in need of a simple job scheduler for my servlet application (no EJB Timers or JMS for me...). The need comes from a requirement stating that certain entries in the database must be scanned for expiration, a piece of code executed for each expired entry, and the database entry must be flagged "done".
Now, I'm aware of real job scheduler tools such as Quartz (open source) or Flux (commercial), but I really don't need anything as feature-rich as those two. The only configuration parameter I need is The Interval, meaning that I don't need multiple timers with complex rules or even cronjobs -- just a number of seconds to sleep between rounds.
Any suggestions?
I've been thinking of the following alternatives:
  • Standalone application polling the database and calling "http://server/expired?id=123" -- ugly but works
  • Starting a thread from a servlet configured with <load-on-startup> -- ugly and against the spec, but would probably work just fine


  • Thanks for the help.
     
    Frank Carver
    Sheriff
    Posts: 6920
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Just to clarify, does this specially have to be "in" the servlet application?
    It would seem that a third choice is a standalone script or small app which accesses the database direct, scheduled by the operating system scheduler.
     
    Lasse Koskela
    author
    Sheriff
    Posts: 11962
    5
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks Frank. That sure is an option as well.
     
    James Swan
    Ranch Hand
    Posts: 403
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    You could implement a context listener that just kicks off a TimerTask to perform your work, that way it's not bound to any servlet etc, and still contained within your appserver code base.
     
    Lasse Koskela
    author
    Sheriff
    Posts: 11962
    5
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Originally posted by James Swan:
    You could implement a context listener that just kicks off a TimerTask to perform your work, that way it's not bound to any servlet etc, and still contained within your appserver code base.
    Ok. I think this is the number one contender so far. I really like keeping the scheduling stuff within the same codebase and avoiding a separate application/configuration to maintain in operation...
     
    Mike Curwen
    Ranch Hand
    Posts: 3695
    IntelliJ IDE Java Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    http://jcrontab.sourceforge.net/index.shtml

    ?

    I use Quartz, but people always seem to mention this project in the same breath.
     
    Lasse Koskela
    author
    Sheriff
    Posts: 11962
    5
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hmm. JCrontab looks interesting. Did I read correctly that JCrontab actually relies on cron (i.e. requires Unix)?
     
    Frank Carver
    Sheriff
    Posts: 6920
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Nah. it just uses a similar specification format.
    From the front page at http://jcrontab.sourceforge.net/ :
    Can be used as a stand-alone application to "replace" cron.
     
    Lasse Koskela
    author
    Sheriff
    Posts: 11962
    5
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Oh, ok. I got the wrong impression of this FAQ answer...
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!