Java Task Scheduler

3

Click here to load reader

Transcript of Java Task Scheduler

Page 1: Java Task Scheduler

Object

This document describes a sample java class that is able to schedule task activities to start at the specified time, and to repeat them at the specified time interval.

Description

Development environment: Eclipse Java EE IDE for Web Developers - Version: Helios Service Release 2 Java Version 1.6.0

util.scheduler.Scheduler

This class schedules the tasks according to the timing specified in properties file parameters.properties. The name of properties file is read as parameter. The main operations performed by this class are: - to read the properties file - to check if one instance of the class is already active, in that case the Scheduler ends - to start and repeat the tasks: Task1, Task2, Task3, … - to catch the event to stop - to wait until all tasks are ended, and then end itself

The class is running until it receives the event to end.The event to end is raised when is created the file specified in the parameter file.to.end in the properties file.

Example:If in the properties file file.to.end=/sample/stop.txt, then when the file stop.txt is created in the folder /sample, le Scheduler ends.

util.scheduler.TaskN where N=1,2,3,…

This class is the activity task.In the method performAction() is defined the activity to execute.

parameters.properties

All parameters are in the properties file: parameters.properties.In the following table are described the parameters:

1

Page 2: Java Task Scheduler

Parameters Description

seconds.wait.active.tasks.end Wait seconds between two successive checks on running tasks before end the Scheduler

seconds.wait.response.verify Wait seconds between two successive checks on the request to end the Scheduler

check.one.instance.active Value: true/false.If true only one instance of the Scheduler can be active

file.to.start Name of the file the Scheduler creates when it starts and deletes when it ends

file.to.end Name of the file that the Scheduler checks when it has been requested to end.This file is deleted by the application just before ending

minutes.to.start.task1 Minutes after that task1 startsminutes.to.repeat.task1 Minutes after that task1 is repeatedminutes.to.start.task2 Minutes after that task2 startsminutes.to.repeat.task2 Minutes after that task2 is repeatedminutes.to.start.task3 Minutes after that task3 startsminutes.to.repeat.task3 Minutes after that task3 is repeated

Example of how to start e repeat activities:

minutes.to.start.task1=0minutes.to.repeat.task1=5

The activity Task1 starts immediately when the Scheduler starts and is re-executed every 5 minutes.

minutes.to.start.task2=1minutes.to.repeat.task2=10

The activity Task2 starts after 1 minute the Scheduler has started and is re-executed every 10 minutes.

minutes.to.start.task3=2minutes.to.repeat.task3=15

The activity Task3 starts after 2 minutes the Scheduler has started and is re-executed every 15 minutes.

Execution

The script scheduler.bat runs the Scheduler.

"c:\Program Files (x86)\IBM\Java60\jre\bin\java.exe" -classpath scheduler.jar util.scheduler.Scheduler parameters.properties

where:

- "c:\Program Files (x86)\IBM\Java60\jre\bin\java.exe": location of java.exe- scheduler.jar: java package - util.scheduler.Scheduler: java class to execute

2

Page 3: Java Task Scheduler

- parameters.properties: properties file

3