jQuery in Action, 3rd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes InterruptedException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "InterruptedException" Watch "InterruptedException" New topic


Praveen Ponna

Joined: Nov 26, 2005
Posts: 11
As per the java doc "java.lang.InterruptedException" is defined as:

Thrown when a thread is waiting, sleeping, or otherwise paused for a long time and another thread interrupts it using the interrupt method in class Thread.

When I was checking for its usage I found it in join() and sleep() method of thread class and wait() method of Object class.

Why not Yield() method of thread?


santhosh sharma

Joined: Jan 29, 2006
Posts: 20
join( ) , wait( ) and sleep( ) send a thread to a waiting state and not a runnable state
whereas yield( ) sends a thread to a runnable state and not in
a waiting state

when you call the interrupt method on that thread , an InterruptedException
is thrown if and only if the thread is not in a runnable state

that is why methods such as join( ) , wait( ) and sleep( ) throw
an InterruptedException

On the other hand when interrupt is called on a thread which
is running or in a runnable state its "interrupt status" is set
(which can be verified using the isInterrupted method in the Thread class)

Setting the "interrupt status" does not affect the state of the
thread in any way and it contines to be in running or runnable state

Hope i hav cleared u r doubt ,

santhosh sharma (scjp 1.4 100%)
I agree. Here's the link: http://aspose.com/file-tools
subject: InterruptedException
It's not a secret anymore!