I started off by installing Java DB from http://developers.sun.com/javadb/downloads/index.jsp . You can start the database either in Single User mode or Multiuser mode (Network Server). There is a good documentation with examples available in the installed directory (
I then have a batch script that starts the network database server whenever I need to.
Next off, I downloaded the quartz1.6.4 version from http://www.opensymphony.com/quartz/download.action and extracted the Jar file to a temp location. Use the script provided in the docs/dbtables/tables_cloudscape.sql to create QRTZ tables needed for storing Job information in the event of System crash/shut down.
Created Wesphere server in RAD/Eclipse and configured the datasource with the Database created above after starting the server and running the admin console. Also created Web, EJB and EAR projects. Added quartz-1.6.4 to the WEB-INF/lib. You will also need Apache common jars in the same location.
The datasource needs to be configured via Resource Reference settings in Web.xml and as JNDI name must be referenced in the ibm-web-bnd.xmi file as below:
< id="ResourceRefBinding_1231272653234" jndiname="jdbc/quartzds">
Configured the quartz.properties as below (showing key properties only)
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.useProperties = false
org.quartz.jobStore.dataSource = quartzDS
org.quartz.jobStore.tablePrefix = QRTZ_
Shut down and Start of scheduler can be specified as init config parameters in Web.xml so that scheduler can be started when web module is deployed and shutdown when it is shut down. I used QuartzInitializerListener for this purpose.
I created another servlet that actually creates the job which invokes the EJB(Session Bean) with parameters as needed (this can be struts action class that can pass neccessary parameters to kick off the batch job that utilize the EJB bean). Set the request recovery flag to true so that Job can recover in the event of System Crash or Shutdown.
For testing purposes, I specified the start time of the job to be 30 seconds later.
trigger.setStartTime(new Date(System.currentTimeMillis() + 30000L));
Then, created the EJB class that does the actual work in the background. Remember to reference the datasource in similiar fashion in the EJB Deployment Descriptor (ejb-jar.xml).
EJB invokes the DAO after getting the connection from Datasource. DAO utilises the connection to insert a new row in sample table (SECONDTABLE) passed as arguments from the Job.
Now, as a test you can invoke the Servlet from browser and shut down the App Server within 30 seconds so that Job information the QRTZ tables (Specifically QRTZ_SIMPLE_TRIGGERS, QRTZ_TRIGGERS, QRTZ_JOB_DETAILS). After 30 seconds have passed, restart the app server and see the job runs automatically and inserts the new row. Once the job runs successfully, data is deleted from the above mentioned QRTZ tables.
That's all folks. This is simple sample real world application that demostrates how quartz can recover in the event of system crash/shut down and re run the job.
There a lot of other features that Quartz offers that is well documented in their website.
The complete source code and batch script can be download from here (Retry download if it fails to download).