aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Thread interrupt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Thread interrupt" Watch "Thread interrupt" New topic
Author

Thread interrupt

Jian Yi
Ranch Hand

Joined: Feb 01, 2002
Posts: 127
Quoted from RHE:

A sleeping thread that recieves an interrupt() call moves immediately into the Ready state; when it gets to run, it will execute its InterruptedException handler.


<pre><font color=#7b007b>
What does it mean "it will execute its InterruptedException handler?" Does it mean an InterruptedException is being caught? Why doesn't it continue to run the run() method?
Thanks,
Jenny
</pre></font>
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
When you call sleep, you must catch the InterruptedException or declare that your method throws it:


Rob
SCJP 1.4
Jian Yi
Ranch Hand

Joined: Feb 01, 2002
Posts: 127
Hi Rob,
Thanks for both of your replies. Your code clarifies the question on InterruptedException. Can you answer my other question of whether the sleeping Thread continues to run after its sleep being interrupted?
Thanks,
Jenny
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
That is up to you and how you write your run() method.
If you write this:

Then after this thread sleeps, the run() method ends. Also, if the thread is interrupted while sleeping, it will end.
This, however, will continue after being interrupted:


And this thread will stop after being interrupted:

So you see, it's completely up to you!
[ March 12, 2002: Message edited by: Rob Ross ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Thread interrupt