How to configure a Quartz service

The standard Quartz-ra service which comes bundled with JBoss is rather limited, or I was not able to find the proper documentation on how to register new jobs on the fly. This article describes how to create a Quartz service which registers the Scheduler via JNDI and access the quartz scheduler directly. Even if all the components are there, this method is also little documented.

 

Note: everything here applies to JBoss 4.2.2GA

Remove the existing Quartz

You need to remove the existing Quartz-ra and quartz.lib

<delete file="${jboss.server}/deploy/quartz-ra.rar" />
<delete file="${jboss.server}/lib/quartz.jar" />

Install the Quartz replacement

You need to

  • copy lib/quartz-1.6.0.jar and lib/quartz-jboss-1.6.0.jar to ${jboss.server}/lib and copy the quartz service definition to  ${jboss.server}/deploy.
  • edit the service definition database configuration
  • create the database tables which are required to store the Quartz state (docs/dbTables/tables_oracle.sql from the standard Quartz distribution)

At this point if you start JBoss you should see your Quartz MBean service

J2EEApplication=null,J2EEServer=Local,ServiceModule=quartz-service.xml,j2eeType=MBean,name=user:service=QuartzService,name=QuartzService

and JNDI name (using the JNDIView > list.

Access Quartz from your code

From your web servlet (as it was my case) you can access Quartz in the following way:

InitialContext ctx = new InitialContext();
Scheduler scheduler = (Scheduler) ctx.lookup("Quartz");

At this point you should be able to use all the Quartz API as you like.

I was explaining here how to create a Quartz job using the standard Quartz-ra service which commes bundled with JBoss. The method is rather limited, or I was not able to find the proper documentation on how to register new jobs on the fly. This is why in this post I will show how to access the quartz scheduler directly.

Note: everything here applies to JBoss 4.2.2GA

Classloading notes

1. If you want for packaging reasons to store your Job definition (class) or make it access other classes in a ear and not the the ${jboss.server}/lib you need to make sure that your Quartz service starts (is deployed) after your ear. You can to this by editing the service definition:

<server>
  <mbean code="org.quartz.ee.jmx.jboss.QuartzService"
      name="user:service=QuartzService,name=QuartzService">
...
        <depends>jboss.j2ee:service=EARDeployment,url='xxx.ear'</depends>
...

2. If you for packaging reasons to store you Job definition (class) or make it access other classes in a war then you should make sure that you understand the JBoss unified classloader which is completely unified now except for the tomcat part. In order to unify it completely then change the line:

<attribute name="UseJBossWebLoader">false</attribute>

in ${jboss.server}/deploy/jboss-web.deployer/META-INF/jboss-service.xml.

Note: ${jboss.server} = ${your jboss path}/server/${your server name}

 

Find the updated source of this article here.

Another article on how to use the standard Quartz-ra service.