Home JBoss Server Developing Quartz MDB
10 | 03 | 2010
JBoss 5 AS Book
"JBoss AS 5 development" reviews
Please share your feedback/review with other readers!
Banner
Dashboard
Advertise with Us
Banner
RSS Feed
Login
Sign here for the NewsLetter.



Poll
What book could be in your wish list next XMas ?
 
JBoss admin resources
Banner
JBoss howto

How can you solve deployment errors caused by large war/jar/ear files ?

jboss recipe of the day ...
Read More

How do you configure your .war to be deployed after your EJB ?

jboss recipe of the day ...
Read More

How do I configure a Queue/Topic to work in a cluster?

JBoss recipe of the day ...
Read More
Developing Quartz MDB PDF Print E-mail
Written by Mark S.   
Wednesday, 29 April 2009 14:18

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! 


JBoss.org Search
Custom Search
Comments
Search
Only registered users can write comments!

3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."

Last Updated ( Wednesday, 29 April 2009 15:16 )