2

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.

zeller
  • 4,904
  • 2
  • 22
  • 40
Rookie
  • 8,660
  • 17
  • 58
  • 91

2 Answers2

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.

Community
  • 1
  • 1
zeller
  • 4,904
  • 2
  • 22
  • 40