Web Age Solutions Inc
Providing Technology Training and Mentoring For Modern Technology Adoption
Web Age Aniversary Logo
US Inquiries / 1.877.517.6540
Canadian Inquiries / 1.877.812.8887

J2EE Scheduler Install Guide

Use this guide to add scheduling to your J2EE application.


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.

<display-name>Scheduler Servlet</display-name>


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 -->

<!-- Run this EJB task every 5 minutes -->

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.

US Inquiries / 1.877.517.6540
Canadian Inquiries / 1.877.812.8887