Rookie
Rookie

Reputation: 8790

Kill a suspended Thread

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.

Upvotes: 2

Views: 1046

Answers (2)

Tom Hawtin - tackline
Tom Hawtin - tackline

Reputation: 147164

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).

Upvotes: 2

zeller
zeller

Reputation: 4974

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.

Upvotes: 2

Related Questions