The following quick tutorial explains how you can have your Quartz Jobs served by an MDB gateway.
JBoss ships with a bundled release of Quartz scheduler. If you need to be introduced to Quartz scheduler I suggest you to read at first the following tutorial:
JBoss quartz tutorial
The following example explains how to schedule stateless or stateful quartz jobs and have the job be posted to a Message Driven bean. The Quartz Resource Adapter creates a non-persistent scheduler.
Jobs are created from deployed MDBs from information in the MDB's activation config spec. At the moment only cron jobs are allowed to be configured.
package com.sample;
import javax.ejb.MessageDriven;
import org.jboss.ejb3.annotation.ResourceAdapter;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import javax.ejb.ActivationConfigProperty;
@MessageDriven(activationConfig =
{@ActivationConfigProperty(propertyName = "cronTrigger", propertyValue = "0 0-5 16 * * ?")})
@ResourceAdapter("quartz-ra.rar")
public class QuartzMDB implements Job
{
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException
{
System.out.println("Quartz job executed!");
}
}
As you can see, it's a simple MDB which implements the Quartz's Job interface. The cronTrigger activation spec attribute is required and its value specifies that a new Job is fired at 4.00 PM every minute until 4.05 PM.
Simply package the class in a jar file and drop it in JBoss "deploy" folder. JBoss will recognize the Bean and display on the console:
16:00:42,382 INFO [EJBContainer] STARTED EJB: com.sample.QuartzMDB ejbName: QuartzMDB
In your console logs you should notice (at 4 PM) :
16:01:00,182 INFO [STDOUT] Quartz job executed!
16:02:00,143 INFO [STDOUT] Quartz job executed!
16:03:00,023 INFO [STDOUT] Quartz job executed!
16:04:00,011 INFO [STDOUT] Quartz job executed!
16:05:00,013 INFO [STDOUT] Quartz job executed!