• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Any way to kill all idle/dead threads?

 
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any ideas?
 
Ranch Hand
Posts: 1871
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
reply
    Bookmark Topic Watch Topic
  • New Topic