Using CronTriggers in the JobInitializationPlugin

Although plug-ins are not discussed until Chapter 8, "Using Quartz Plug-Ins," it's worth jumping ahead to show how CronTriggers can be used within the quartz_jobs.xml file to specify job information. The JobInitializationPlugin can be used to load job information from an XML file.

Just as with SimpleTriggers, you can specify CronTrigger expressions in the XML file, and the Quartz Scheduler will use this information to schedule your jobs. This is extremely convenient if you want to declare your job information externally to your application code. Listing 5.3 shows the quartz_jobs.xml file that is used with the JobInitializationPlugin to load job information.

Listing 5.3. CronTriggers Can Be Specified in an XML File and Loaded with the JobInitializationPlugin

PrintInfoJob DEFAULT A job that prints out some basic information. org.cavaness.quartzbook.common.PrintInfoJob printJobInfoTrigger DEFAULT PrintInfoJob DEFAULT 0 30 7 ? * MON-FRI

The cron expression shown in Listing 5.3 is the same one from Listing 5.1. When Quartz loads the XML file, it will schedule the PrintInfoJob (also listed in the XML file) to execute at 7:30 AM Monday through Friday. More is said about the JobInitializationPlugin in Chapter 8.

Cron Expressions Cookbook

Категории