pulsar2

J2EE Scheduler Install Guide

Use this guide to add scheduling to your J2EE application.

Basics

The scheduler runs as a servlet. To add sechduling support to your application, you will need to add the scheduler servlet to one of the web modules of the application. The schedule is defined in the WEB-INF/schedule.xml file of the web module where the scheduler servlet is defined.

Each job in the schedule is called a Task. A task can be implemented by a plain Java class or a Stateless Session EJB. See the development guide for how to develop your own tasks.

Supported Platforms

The code has been tested with WebSphere Application Server 4.0.3. You are free to change the code to support other platforms.

Install Scheduler Code

Add the downloaded scheduler.jar file to the root directory of the enterprise application (EAR). Build a module dependency between the web module where the scheduler servlet will be installed and scheduler.jar. This is done by opening the META-INF/MANIFEST.MF file of the web module and adding the scheduler.jar file to the class path. If you have an EJB task, make sure that you add the EJB module to the class path as well. An example MANIFEST.MF file will be as follows.

Manifest-Version: 1.0
Class-Path: scheduler.jar ScheduleTestEJB.jar

Add Scheduler Servlet

You will need to add the scheduler servlet to one of the web modules of your enterprise application. Edit the WEB-INF/web.xml file of the web module and add the servlet as follows.

<servlet>
<servlet-name>Scheduler</servlet-name>
<display-name>Scheduler Servlet</display-name>
<servlet-class>com.webage.scheduler.SchedulerServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>Scheduler</servlet-name>
<url-pattern>/Scheduler</url-pattern>
</servlet-mapping>

Note that the class name of the servlet is com.webage.scheduler.SchedulerServlet. The servlet is setup to initialize on startup of the web module.

Prepare The Schedule

The scheduled tasks and their frequencies are defined in the WEB-INF/schedule.xml of the web module where you have added the scheduler servlet.

A typical schedule.xml file will look like this.

<!-- Look for an updated version of this file every 30 minutes -->
<schedule reload="30">

<!--Execute a Java class every 10 minutes -->
<task 
type="Java" 
id="com.webage.scheduler.TestTask"
frequency="10"
/>

<!-- Run this EJB task every 5 minutes -->
<task 
type="EJB" 
id="ejb/com/webage/ejbs/TestTask"
frequency="5"
/>
</schedule>

Two types of tasks are supported – “Java” and “EJB”. The “id” attribute specifies the class name for a Java class task and JNDI name for an EJB task. The “frequency” attribute specifies how often the task will be executed. The unit of time is minutes.

Setting Class Path

The scheduler code uses xerces.jar. Also, the task Java classes need to be visible to the scheduler servlet. Use standard J2EE techniques to add xerces.jar and other necessary code to the class path of the web module that runs the scheduler servlet.

Starting and Stopping The Scheduler

To start the schedule, simply start the web module that contains the scheduler servlet. The schedule configuration file WEB-INF/schedule.xml will be loaded on startup. If there is an error in the XML file, system will print an error message in the standard output and terminate the scheduler.

Currently, the schedule file is loaded on startup only.

To stop the schedule, shutdown the web application that contains the scheduler servlet.

Sample Application

You can install the sample application packaged in ScheduleTest.ear in your application server. The EAR file is currently packaged for WebSphere Application Server 4.0.3.