• Post Reply Bookmark Topic Watch Topic
  • New Topic

interrupt() method

 
Rashmi Tambe
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While i was reading dicussion threads in this forum , i came across one statement :

Calls to interrupt() are stored i.e. if interrupt() is called on a thread which is not blocked by sleep, wait, join etc. and doing something else, then it will continue with the work. When the thread, on which interrupt () was called, calls any of the above-mentioned methods, it will be interrupted immediately.

U can refer to this here : http://www.javaranch.com/ubb/Forum27/HTML/000131.html
I don't understand if interrupt() is called, then the thread has to be interrupted immediately. No matter what it is executing! Otherwise what's the use of interrupt() ? How is it possible that the thread will continue running and when it calls wait(), sleep() etc. it is interrupted ? I am confused with the purpose of interrupt() because of this quote.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rashmi Gunjotikar:
I don't understand if interrupt() is called, then the thread has to be interrupted immediately. No matter what it is executing! Otherwise what's the use of interrupt()?

What you want is basically the functionality of <code>Thread.stop()</code>. This method has been deprecated, and with good reason. Please look up the API documentation for an explanation why stopping (or interrupting) code at arbitrary points is inherently dangerous, evil, and otherwise objectionable.
- Peter
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!