wood burning stoves 2.0*
The moose likes Threads and Synchronization and the fly likes Any way to kill all idle/dead threads? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Any way to kill all idle/dead threads?" Watch "Any way to kill all idle/dead threads?" New topic
Author

Any way to kill all idle/dead threads?

Matt Senecal
Ranch Hand

Joined: Dec 01, 2000
Posts: 255
Any ideas?


There's nothing more dangerous than a resourceful idiot. ---Dilbert
Rahul Mahindrakar
Ranch Hand

Joined: Jul 28, 2000
Posts: 1849
Matt,
Lets talk about dead threads
Dead threads are threads that have completed their run() method. Now these threads cannot be started again as you know. Thus to "kill" the thread you will have to remove or make null any reference that exists to this thread object. The garbage collector will do it job of garbage collection.
About Idle threads
Idle thread are threads what do some work and wait for some event to continue working. To do this your program should contain the logic to exit the run method cleanly based on condition. It is not proper programming logic for you to "kill" a thread.
The concept of "kill" of a thread has thus been "deprecated" if you check up the 1.2 api with the "deprecation" of the stop method and other methods.
------------------

Mahindrakar
IBM Application Server Forum Moderator
Consultant - Zensar Technologies.
SCJP2, SCJD2 & SCJEA (Part I)
jeremy crosbie
Greenhorn

Joined: Jun 20, 2001
Posts: 23
Originally posted by Matt Senecal:
Any ideas?

Dead threads are, well, dead. They have been killed
As far as idle threads the APIs for stopping threads have been deprecated. Reason being is that they were unsafe: if someone called Thread.stop() while the thread was performing work the state in which the thread terminates is unknown potentially causing bad results.
What you can do is inside the class that implements Runnable or extends the Thread class is add a boolean flag. Normally that flag is set to false but when set to true the thread should be made to recognize it and stop gracefully.
hope this helps.

Jeremy Crosbie<BR>Co-Author of <A HREF="http://www.amazon.com/exec/obidos/ASIN/186100401X/ref=ase_electricporkchop" TARGET=_blank rel="nofollow">Professional Java XML</A>
Matt Senecal
Ranch Hand

Joined: Dec 01, 2000
Posts: 255
Thanks to the both of you!
Originally posted by jeremy crosbie:
Dead threads are, well, dead. They have been killed
As far as idle threads the APIs for stopping threads have been deprecated. Reason being is that they were unsafe: if someone called Thread.stop() while the thread was performing work the state in which the thread terminates is unknown potentially causing bad results.
What you can do is inside the class that implements Runnable or extends the Thread class is add a boolean flag. Normally that flag is set to false but when set to true the thread should be made to recognize it and stop gracefully.
hope this helps.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Any way to kill all idle/dead threads?
 
Similar Threads
[eclipse] any good .html plugin that you recommend?
Page implicit Object?
Unadulterated petrol pumps in bangalore
Suggestions for team cheer
unable to add App Project into testServer