This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes How to kill Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "How to kill Threads" Watch "How to kill Threads" New topic
Author

How to kill Threads

Pash Sonar
Greenhorn

Joined: May 25, 2005
Posts: 7
Hi,

I want to kill a thread while executing after some time. How to kill the thread in middle. (stop and destroy methods are deprecated, so dont use)

If any body knows the solution plz help me
Sameer Amte
Ranch Hand

Joined: Oct 22, 2002
Posts: 38


The above code should help in stopping a thread gracefully or in a forced mode. If your thread is in a wait state then an InterruptedException will be raised in which you should break out of your while loop to terminate your thread.
Pash Sonar
Greenhorn

Joined: May 25, 2005
Posts: 7
Originally posted by Sameer Amte:


The above code should help in stopping a thread gracefully or in a forced mode. If your thread is in a wait state then an InterruptedException will be raised in which you should break out of your while loop to terminate your thread.
Yaroslav Chinskiy
Ranch Hand

Joined: Jan 09, 2001
Posts: 147
I suggest to make continueRunning volatile.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: How to kill Threads
 
Similar Threads
how to kill a thread in MIDP
Kill a thread
killing a Thread ?
Soap thread
how to kill main thread and relative subthread?