wood burning stoves 2.0*
The moose likes Threads and Synchronization and the fly likes TimerTask.cancel() not killing tasks in the webcontainer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "TimerTask.cancel() not killing tasks in the webcontainer" Watch "TimerTask.cancel() not killing tasks in the webcontainer" New topic

TimerTask.cancel() not killing tasks in the webcontainer

Chetan Mishra

Joined: Sep 09, 2003
Posts: 8

I have a java programme which creates timer tasks and runs 5 tasks[scheduled to run continueously]. I have this deployed as a web module in an appliction, deployed in WAS 5.1.

These tasks are to be started automatically when the application is started and should be killed when the application is brought down [And not the application server]. So, invoking this in init() of statup servlet and killing in destroy() of the servlet by calling cancel() of TimerTask class.

But this cancel() doesn't seems to work here [inside the web container]. When the same programme executed out side container [as a standalone application], cancel() actually kills the taks.

Points to be noted here is i cannot put this cancel() inside the run() of each task. So will have to call on the instance of the TimerTask object.

Can any one let me know what could be the issue.
How can i kill all these timer tasks inside the webcontainer.

Thanks & Regards,
It is sorta covered in the JavaRanch Style Guide.
subject: TimerTask.cancel() not killing tasks in the webcontainer
Similar Threads
Thread Scheduler
How to stop a Timer after it's run more than once?
TimerTask, Threads and Servlets
How to Start a service automatically when the tomcat starts?
questions java.util.Timer