QuartzSchedulerIntegration

Quartz Scheduler Integration

 

If you have installed JBoss using the 4.0.4.GA installer it comes bundled with Quartz integration packaged as a JCA Message-Inflow resource adapter: quartz-ra.rar.

This resource adapter is also present in JBoss 4.2.0 or later.

 

This integration allows you 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.  Currently only cron jobs are allowed to be configured.  In future versions we will support other activation config spec setting for Quartz.

 

Here's an example:

import org.jboss.annotation.ejb.ResourceAdapter;
import org.jboss.logging.Logger;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import javax.ejb.MessageDriven;
import javax.ejb.ActivationConfigProperty;

@MessageDriven(activationConfig =
{
   @ActivationConfigProperty(propertyName="cronTrigger", propertyValue="0/2 * * * * ?")
})
@ResourceAdapter("quartz-ra.rar")
public class AnnotatedQuartzMDBBean implements Job
{
   private static final Logger log = Logger.getLogger(AnnotatedQuartzMDBBean.class);


   public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException
   {
      AnnotatedQuartzMDBBean.log.info("************** here in annotated!!!!");
   }
}

    

This is a simple MDB that implements the org.quartz.Job interface.  The "cronTrigger" activation spec attribute is required.  In this you specify a cron syntax as documented in the Quartz distribution.  The @org.jboss.annotation.ejb.ResourceAdapter annotation is used to tell the EJB container which resource adapter to use for the inflow implementation.

 

If you remove the annotations, this can also be specified in ejb-jar.xml and in jboss.xml.  ejb-jar.xml is responsible for setting up the activation config spec, while jboss.xml defines the resource adapter binding. Here are some examples of ejb-jar.xml and jboss.xml adnotation equivalents.