How to get all the suspended threads and kill them? I am working on a web application which starts a thread named TImer-0 which is suspended most of the times.When i terminate the apache server it shows that SEVERE: The web application [/LoggingMonitor] appears to have started a thread named [Timer-0] but has failed to stop it. This is very likely to create a memory leak.
Asked
Active
Viewed 1,007 times
2
-
Is it suspended with Thread.suspend? Or do you mean it's generally not doing any activity? – Tudor Jan 02 '12 at 13:51
-
this is a follow up to: http://stackoverflow.com/questions/8677008/catalina-out-memory-leak-error – oers Jan 02 '12 at 13:54
-
1Let the container manage the threads. It will save you a lot of pain in the long run. – Thorbjørn Ravn Andersen Jan 02 '12 at 13:59
-
actually catalina is showing this problem. – Rookie Jan 02 '12 at 14:00
-
i don think that there is some bug in tomcat or is it? – Rookie Jan 02 '12 at 14:11
-
Daemon Thread [Timer-0] (Suspended) TimerThread.mainLoop() line: not available [local variables unavailable] TimerThread.run() line: not available – Rookie Jan 02 '12 at 14:16
-
This is the trace.All other threads are running but this thread is suspended and causing the problem – Rookie Jan 02 '12 at 14:17
2 Answers
2
You really don't want to suspend threads, as that may stop the entire process working. Even if you do have suspended threads, stopping them is not likely to help.
Timer-n
sounds like java.util.Timer
. This can be cleaned up by calling cancel
. So long as you don't have a memory leak, the thread should be collected eventually (cancelled by a finalizer
).

Tom Hawtin - tackline
- 145,806
- 30
- 211
- 305
-
i didnt suspend the thread.When i debugged the application it showed that all other threads were running but timer-o thread was suspended most of the times – Rookie Jan 02 '12 at 14:02
-
i am using timer.cancel() in onContextDestroyed of servlets,is that ok? – Rookie Jan 02 '12 at 14:03
2
You shouldn't kill the thread, instead free the resources (memory excluded since it is freed by the gc) it uses and let the scheduler stop it . Thread.stop is deprecated (just as suspend).
If you have to stop the thread manually use a flag as seen here or here in the answers.