JBoss.org Community Documentation
JBossAS comes bundled with Quartz integration packaged as a JCA Message-Inflow resource adapter quartz-ra.rar.
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
the information in the MDB's activation config spec.
Currently only cron jobs are allowed to be configured.
Take a look at the org.jboss.tutorial.jca_inflow_quartz.bean.AnnotatedQuartzMDBBean:
@MessageDriven(activationConfig =
{@ActivationConfigProperty(propertyName = "cronTrigger", propertyValue = "0/2 * * * * ?")})
@ResourceAdapter("quartz-ra.rar")
public class AnnotatedQuartzMDBBean implements Job
{
...
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 documentation.
The @org.jboss.ejb3.annotation.ResourceAdapter annotation is used to tell the EJB container which
resource adapter to use for the inflow implementation.
Instead of using annotations, you can also use a deployment descriptor to configure the MDB for Quartz
integration. Take a look at META-INF/ejb-jar.xml and META-INF/jboss.xml
The ejb-jar.xml configures the cronTrigger through the <activation-config>
element:
<message-driven>
<ejb-name>ExampleMDB</ejb-name>
<ejb-class>org.jboss.tutorial.quartz.bean.QuartzMDBBean</ejb-class>
<transaction-type>Container</transaction-type>
<activation-config>
<activation-config-property>
<activation-config-property-name>cronTrigger</activation-config-property-name>
<activation-config-property-value>0/2 * * * * ?</activation-config-property-value>
</activation-config-property>
</activation-config>
</message-driven>
The jboss.xml configures the resource-adapter-name :
<message-driven> <ejb-name>ExampleMDB</ejb-name> <resource-adapter-name>quartz-ra.rar</resource-adapter-name> </message-driven>
To build and run the example, make sure you have installed JBoss 5.x. See the Section 1.1, “JBoss Application Server 5.x” for details.
From the command prompt, move to the "jca_inflow_quartz" folder under the Section 1.3, “Set the EJB3_TUTORIAL_HOME”
Make sure the "default" server configuration of JBossAS-5.x is running
$ ant
This will deploy the jar into the JBossAS-5.x server ("default" configuration).
$ mvn clean package
This will create the jar in the target folder of the tutorial. Copy this jar to the deploy folder of JBossAS-5.x
On the server side when the application is deployed, you will notice these logs:
18:46:57,053 INFO [QuartzMDBBean] ************** JOB: job.4.1232457416127 18:46:58,023 INFO [AnnotatedQuartzMDBBean] ************** here in annotated!!!! 18:46:58,026 INFO [QuartzMDBBean] ************** JOB: job.2.1232457416077 18:47:00,019 INFO [AnnotatedQuartzMDBBean] ************** here in annotated!!!! 18:47:00,021 INFO [QuartzMDBBean] ************** JOB: job.2.1232457416077 18:47:00,023 INFO [QuartzMDBBean] ************** JOB: job.4.1232457416127 18:47:02,020 INFO [AnnotatedQuartzMDBBean] ************** here in annotated!!!! 18:47:02,023 INFO [QuartzMDBBean] ************** JOB: job.2.1232457416077 18:47:03,019 INFO [QuartzMDBBean] ************** JOB: job.4.1232457416127 18:47:04,022 INFO [AnnotatedQuartzMDBBean] ************** here in annotated!!!! 18:47:04,024 INFO [QuartzMDBBean] ************** JOB: job.2.1232457416077 18:47:06,019 INFO [AnnotatedQuartzMDBBean] ************** here in annotated!!!! 18:47:06,021 INFO [QuartzMDBBean] ************** JOB: job.2.1232457416077 18:47:06,024 INFO [QuartzMDBBean] ************** JOB: job.4.1232457416127 18:47:08,019 INFO [AnnotatedQuartzMDBBean] ************** here in annotated!!!! 18:47:08,021 INFO [QuartzMDBBean] ************** JOB: job.2.1232457416077 18:47:09,020 INFO [QuartzMDBBean] ************** JOB: job.4.1232457416127