• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to kill a thread within itself?  RSS feed

 
John Landon
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
How to kill a thread within itself. Just kill it immediately without any conditions and cleaning.

Thanks!
 
Tim Moores
Saloon Keeper
Posts: 4034
94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just return from the run() method.
 
John Landon
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 344
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!