Using TriggerUtils with the CronTrigger
Chapter 4, "Scheduling Jobs," introduced the triggerUtils class in the org.quartz package, which simplifies the creation of triggers of both types. When possible, you should attempt to use the methods within the triggerUtils class to create your triggers.
For example, if you needed to execute a job every day at 5:30 PM, you could use the following code:
try { // A CronTrigger that fires @ 5:30PM CronTrigger trigger = new CronTrigger("CronTrigger", null, "0 30 17 ? * *"); } catch (ParseException ex) { logger.error("Couldn't parse cron expression", ex); }
Or you could use the triggerUtils like this:
// A CronTrigger that fires @ 5:30PM Trigger trigger = TriggerUtils.makeDailyTrigger(17, 30); trigger.setName("CronTrigger");
TRiggerUtils makes it easier and more convenient to use triggers, without giving up too much of the flexibility.
Using CronTriggers in the JobInitializationPlugin
|