• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threads & Interrupt Method...

 
Shah Chunky
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hello All...
Can someone Explain me What exactly is the Meaning of Interrupt Method...
I am referring Java 2 Cert - RHE (1999 Edition)
According to the book, On page 204 (at end of the page) it says that
"If a thread might need to be killed from Another Thread, then u should send it an
interrupt from Killing method."

On page 210 (just before the Figure 7.3) it says that
"A sleeping thread that receives an interrupt() call moves immediately into Ready State."

What i don't understand is that according to page 204, the method Interrupt will kill the thread
& according to page 210, the interrupt() will make the sleeping thread move it to Ready state
which according to my knowledge means the thread is not killed.
Can someone explain ?
Thanks.
 
lee dalais
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Shah
from my understanding:
what interrupt() does is that it temporarely suspends the currently running thread, to give the thread schedular a chance to check if there are any other threads(generally higher priority threads) that it can put into the running state, if not, then the currently running thread carries on running.
 
Sean Casey
Ranch Hand
Posts: 625
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lee, the method you describe is the static yield method. The interrupt method is used in place of the deprecated stop() method from an earlier version of the jdk. So for a thread in a running state, it will interrupt that the currently running state. If it is sleeping then a call to the method will interrupt the sleeping thread, and return it to a ready state. I'm not sure about exceptions thrown. The interrupt() is an instance method of class Thread.
 
lee dalais
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks sean for the correction, i reassesed/reread what i wrote and realized that i was describing the wrong method.
thank u again
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic