Friday, September 10, 2010

Quartz Jobs.xml Example - Adding a Durable Job

The following sample XML shows how to set up a single Quartz job without a trigger in a jobs.xml configuration file. I first tried just creating a job without any trigger associated with it, but I got a runtime error:

Error scheduling jobs: A new job defined without any triggers must be durable...A new job defined without any triggers must be durable...

The following scheduled job is called SampleJob. The one tricky catch is that in order to set the job as durable, you also have to include the volatility AND recover elements. 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>
            <volatility>false</volatility> 
            <durability>true</durability> 
            <recover>false</recover> 
            <job-data-map>
                <entry>
                    <key>Param1</key>
                    <value>N</value>
                </entry>
            </job-data-map>
        </job>            
    </schedule>
</job-scheduling-data>



Piece of Cake!!!

No comments: