I’m working on a stand alone java application that needs some fairly sophisticated scheduling capabilities, more than java.util.Timer can provide. Normally, I’d reach for trusty old cron, but in this case, it’s a java program that needs to be run on both unix and windows with a minimum of fuss.
Quartz to the rescue. This open source java package lets you schedule a myriad of executable objects in many different ways. There are many different ways to use Quartz; there’s a nice tutorial here, and the Quartz javadoc is pretty up to date.
All I’m using it for is a cross-platform cron replacement, but it does seem to have large number of other features. The one that I’m not using that seems the most useful is the ability to differentiate between activities (a Job) to be scheduled, and the events, be they time or otherwise related, that should cause those activities to be executed (a Trigger). Nice orthogonality, but for my purposes, overkill. However, I can see the usefulness of this feature.
The coolest feature that I am using is JobExecutionContext.getScheduler() which allows any job running to access the scheduler in which they are running. They can delete themselves, verify that other jobs are working, and even shutdown the scheduler.
If you have to do scheduling in java, you should take a look at Quartz. (Here is a survey of job scheduling options in Java.)
We just used Quartz at my last gig and while it is nice it lacks one VERY important feature and that is the ability for none-cron speakers to schedule a job. Basically what we had to do is create a web interface that allows any Joe or Betty to create a cron expression that Quartz then uses. That was an amazing pain the ass. I wish the team I was on could open source that code we wrote. Otherwise how to you plan on getting the cron expression into the system? I would love to hear what others have done here!