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 Java in General and the fly likes How to kill a thread within itself? 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 » Java in General
Reply Bookmark "How to kill a thread within itself?" Watch "How to kill a thread within itself?" New topic
Author

How to kill a thread within itself?

John Landon
Ranch Hand

Joined: Sep 25, 2008
Posts: 221
Hi,
How to kill a thread within itself. Just kill it immediately without any conditions and cleaning.

Thanks!
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2407
Just return from the run() method.
John Landon
Ranch Hand

Joined: Sep 25, 2008
Posts: 221
Tim Moores wrote:Just return from the run() method.


cant do that if it is not returning form a O/I call....
Koen Aerts
Ranch Hand

Joined: Feb 07, 2012
Posts: 344

Not sure what I/O activities your thread is doing, but does the I/O function have some sort of timeout handling that you can use? That would probably be the best way to handle this (right at the source), if possible.
John Landon
Ranch Hand

Joined: Sep 25, 2008
Posts: 221
Koen Aerts wrote:Not sure what I/O activities your thread is doing, but does the I/O function have some sort of timeout handling that you can use? That would probably be the best way to handle this (right at the source), if possible.


Thanks for your input :-) but it's like saying. "if you are getting robbed in the valley maybe you can call 911 instead of giving out your money". If it was the case I wouldn't ask the question.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16687
    
  19

John Landon wrote:
Koen Aerts wrote:Not sure what I/O activities your thread is doing, but does the I/O function have some sort of timeout handling that you can use? That would probably be the best way to handle this (right at the source), if possible.


Thanks for your input :-) but it's like saying. "if you are getting robbed in the valley maybe you can call 911 instead of giving out your money". If it was the case I wouldn't ask the question.



Sorry, but I don't get the analogy....


Anyway, other options... If your JVM supports Interrupted I/O, then you can interrupt it from another thread, and have the I/O thread deal with the InterruptedIOException. If the intent is to close the I/O channel anyway, you can close the channel from another thread, and have the I/O thread deal with the I/O exception..... otherwise, your only option (that I see at the moment), is to set a flag; then in the future, if / when this I/O thread comes back, it checks the flag, and stops whatever it is doing, to return from the run method. You can't stop the I/O but you can prevent any further unwanted behavior.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to kill a thread within itself?
 
Similar Threads
how to kill a thread in MIDP
Help with Timer
killing a Thread ?
Java threads
Soap thread