File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Any way to kill all idle/dead threads?

 
Matt Senecal
Ranch Hand
Posts: 255
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any ideas?
 
Rahul Mahindrakar
Ranch Hand
Posts: 1868
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Matt Senecal
Ranch Hand
Posts: 255
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic