File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Java 8 in Action this week in the Java 8 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,
I agree. Here's the link:
subject: TimerTask.cancel() not killing tasks in the webcontainer
Similar Threads
TimerTask, Threads and Servlets
How to Start a service automatically when the tomcat starts?
Thread Scheduler
How to stop a Timer after it's run more than once?
questions java.util.Timer