Task scheduling for the J2EE applications
| Introduction |
|
Task scheduling is a common need in enterprise applications and is used to provide various kinds of functionality – reminders, batch transfers, notifications etc. This document explains the implementation of a task-scheduling component that can be used by J2EE applications. The component makes use of the Message Driven Model in EJB 2.0 specification and JDK 1.3. |
| Architecture |
The architecture of the component is explained below:
The ‘Task Trigger’ is a component or a set of components that decide the time of execution for a scheduled task and provides the scheduled application the required information for execution. The ‘subscriber id’ is the id of the application that has to run at the time of execution. The ‘Task Trigger’ invokes the ‘Task scheduler’ using RMI and passes the time of execution, the subscriber id and the required information. The task triggers themselves perform a set of tasks one of which is scheduling a task. The required information is used by the applications that execute the scheduled tasks. It can be passed as any object. The ‘File Transfer Application’ and the ‘Reminder Application’ run at scheduled times. They are implemented as Message Driven Beans (specified in EJB 2.0 specification). They subscribe to the Timer Message Bus. They pick up any message written to the message bus. If the subscriber id matches the subscriber, the message body is read and the task is executed. |
| The task scheduler |
|
The task scheduler component uses the java.util.Timer class specified in JDK 1.3 to schedule tasks. The Timer object creates threads to schedule tasks. For this reason, it should not be called or created directly by EJBs, JSPs or servlets (see J2EETM SDK documentation and J2EE Blueprints). Hence, it implemented as a RMI service that can exist at any location in the application server’s JNDI namespace. The java.util.Timer class scales to large numbers of concurrently scheduled tasks (thousands should present no problem). Internally, it uses a binary heap to represent its task queue, so the cost to schedule a task is O(log n), where n is the number of concurrently scheduled tasks. (Source: JDK1.3 API Documentation) The task scheduler may or may not be deployed within the same application server(s) as the J2EE application. In either case, the RMI stub should be available to the task triggers. The task scheduler writes a message with the subscriber id and the required information on the Timer Message Bus at the specified time of execution for a task. The subscriber id is passed as a String property of the JMS Message object itself. The information passed from the task trigger application forms the message body. The task scheduler does not concern itself with the semantics of the subscriber id or the object being passed. It is only concerned with the scheduling of the task using the execution time(s) specified. The task scheduler exposes interfaces for the task trigger to schedule tasks in different ways. Tasks could be scheduled to run
|
| Deploying the RMI Server for the Scheduler |
c:\jdk1.3\bin\rmiregistry java com.planetasia.timer.SchedulerServer |
| Using the Scheduler |
The following points should be noted while developing applications using the scheduler.
|
| Known issues at time of publishing |
|
| Please contact me at vikramr@planetasia.com for comments and suggestions. |