How can a running scheduled task be stopped?
To get the stop mechanism to work for a schedule task, the Schedule Task process must be implemented to periodically check for the stop flag and respond to it. Since killing threads is not a good idea, stop schedule task is only a request to stop the task. Schedule tasks can only be stopped if they are written to honor stop requests.
This can be done in two ways:
• ScheduleTask can implement the stop( ) method. This returns a boolean value (true/false) to be compatible with 7.2.x, but the return value doesn't mean or represent anything.
• ScheduleTask can call isStopped() method to find out, if a stop request is pending.
How stop works:
To stop a schedule task, select the 'Stop Execution' check box and click on save.
The Task Bean (tcTSK) will detect that the save is to stop the task, by looking at the value of the check box. TSK bean locates the Scheduler Controller and issues a stop request. After the stop request is successfully issued, it disables the task, and clears the 'Stop Execution' check box.
When the Scheduler Controller receives the stop notification, it looks in the local tasks directory to see if the scheduler on this machine is running the task. If so, it sets the stopPending flag for the task and calls the stop( ) method in the scheduler.
If Schedule Task is not executing in the local machine, it sends a group notification to all the schedulers to stop the schedule task. Each Scheduler looks at the local active task list and stops the task if it is running the task. Otherwise they will ignore the message.
Group Notification:
All schedulers join a MultiCast group on the startup. The Group name is alwaus "ScheduleTasks", and they discover each other using the multicast-IP configured in xlconfig.xml file.
<Scheduler>
<MultiCastAddress>999.999.999.999</MultiCastAddress>
Use this setting to define the same multicast address for all machines running scheduler.
We are using JavaGroups API to join the cluster. JavaGroups will also take care of removing the group members as they are stopped.