Saturday, August 21, 2010

Quartz Jobs.xml Example - Single Job Multiple Triggers with CRON Expression

The following sample XML shows how to set up a single Quartz job with multiple cron triggers in a jobs.xml configuration file. The scheduled job is called SampleJob and it has two triggers Trigger1 and Trigger2. The job has its own parameter and each trigger has its own parameter. Trigger1 runs every day at 9:00 and Trigger2 runs every day at 10:00. This works for sure with Quartz version 1.8.3.

<?xml version='1.0' encoding='utf-8'?>
<job-scheduling-data xmlns="http://www.quartz-scheduler.org/xml/JobSchedulingData"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.quartz-scheduler.org/xml/JobSchedulingData http://www.quartz-scheduler.org/xml/job_scheduling_data_1_8.xsd"
  version="1.8">

    <schedule>
        <job>
            <name>SampleJob</name>
            <group>DEFAULT</group>
            <job-class>com.xyz.SampleJob</job-class>
            <job-data-map>
                <entry>
                    <key>Param1</key>
                    <value>HOT</value>
                </entry>
            </job-data-map>
        </job>
        <trigger>
            <cron>
                <name>Trigger1</name>
                <group>DEFAULT</group>
                <job-name>SampleJob</job-name>
                <job-group>DEFAULT</job-group>
                <job-data-map>
                <entry>
                    <key>Param2</key>
                    <value>Y</value>
                </entry>
                </job-data-map>
                <cron-expression>0 0 9 * * ?</cron-expression>
            </cron>
        </trigger>
        <trigger>
            <cron>
                <name>Trigger2</name>
                <group>DEFAULT</group>
                <job-name>SampleJob</job-name>
                <job-group>DEFAULT</job-group>
                <job-data-map>
                <entry>
                    <key>Param2</key>
                    <value>N</value>
                </entry>
                </job-data-map>
                <cron-expression>0 0 10 * * ?</cron-expression>
            </cron>
        </trigger>
    </schedule>
</job-scheduling-data>



Piece of Cake!!!

4 comments:

Anonymous said...

Perfect - your example saved me from digging through the whole XSD.

thx a lot

Tim Molter said...

Glad it helped!! Thanks for stopping by.

Anonymous said...

Is it possible to set a priority for a trigger in the xml file ?

Tim Molter said...

Anonymous, good question, don't know the answer though. Sorry ;-|