• Post Reply Bookmark Topic Watch Topic
  • New Topic

simple Q about thread.interrupt()  RSS feed

 
Raymond
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,

I just have one simple Q about thread.interrupt(). I wonder what thread.interrupt() really does in the java program. from the name, I guess it is used when we would like to interupt the thread excution. But when I read some meterial in the internet, it is said it wakes the thread up(Wake up a sleeping thread or blocked thread).

Can anyone please enlighten me on this question.

Thanks a lot.

Raymond
[ September 26, 2004: Message edited by: Raymond ]
 
Warren Dew
blacksmith
Ranch Hand
Posts: 1332
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The material you have read is correct.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The interrupt() method will cause a wait() or sleep() method to stop blocking and throw InterruptedException. There may be a few other such methods, but unfortunately I/O is not included; you cannot unblock a read() on a stream by using interrupt().

If the Thread on which interrupt() is called is not in one of the System methods that respond to it, then user code can see that the interrupt has happened, by using isInterrupted() or interrupted(). It is then up to the user code to do decide what to do.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!