aspose file tools*
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


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

INTERRUPTEDEXCEPTION

Shafkat Talli
Ranch Hand

Joined: Aug 01, 2003
Posts: 30
-Both wait and sleep method throws a InterruptedException, do we need to know for the exam how InterruptedException can happen ? if so, anyone got a answer ?


---------------------------<br />Shafkat Talli<br />SCJP 1.4, August 2003.
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
quotes from API

interrupt
public void interrupt()
Interrupts this thread.
First the checkAccess method of this thread is invoked, which may cause a SecurityException to be thrown.
If this thread is blocked in an invocation of the wait(), wait(long), or wait(long, int) methods of the Object class, or of the join(), join(long), join(long, int), sleep(long), or sleep(long, int), methods of this class, then its interrupt status will be cleared and it will receive an InterruptedException.
If this thread is blocked in an I/O operation upon an interruptible channel then the channel will be closed, the thread's interrupt status will be set, and the thread will receive a ClosedByInterruptException.
If this thread is blocked in a Selector then the thread's interrupt status will be set and it will return immediately from the selection operation, possibly with a non-zero value, just as if the selector's wakeup method were invoked.
If none of the previous conditions hold then this thread's interrupt status will be set.
Throws:
SecurityException - if the current thread cannot modify this thread


join
public final void join()
throws InterruptedException
Waits for this thread to die.
Throws:
InterruptedException - if another thread has interrupted the current thread. The interrupted status of the current thread is cleared when this exception is thrown.


sleep
public static void sleep(long millis)
throws InterruptedException
Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds. The thread does not lose ownership of any monitors.
Parameters:
millis - the length of time to sleep in milliseconds.
Throws:
InterruptedException - if another thread has interrupted the current thread. The interrupted status of the current thread is cleared when this exception is thrown.


wait
public final void wait()
throws InterruptedException
Causes current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object. In other words, this method behaves exactly as if it simply performs the call wait(0).
The current thread must own this object's monitor. The thread releases ownership of this monitor and waits until another thread notifies threads waiting on this object's monitor to wake up either through a call to the notify method or the notifyAll method. The thread then waits until it can re-obtain ownership of the monitor and resumes execution.
This method should only be called by a thread that is the owner of this object's monitor. See the notify method for a description of the ways in which a thread can become the owner of a monitor.
Throws:
IllegalMonitorStateException - if the current thread is not the owner of the object's monitor.
InterruptedException - if another thread has interrupted the current thread. The interrupted status of the current thread is cleared when this exception is thrown

Hope it helps


SCJP2. Please Indent your code using UBB Code
Shafkat Talli
Ranch Hand

Joined: Aug 01, 2003
Posts: 30
if a thread throws a interruptedexception, what happends with the thread, does it die ? or does it go back to runnable, or does it still wait ?
Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
Hi Shafqat:
I think it goes to ready to run state and wait for its turn at cpu.
Barkat
 
Don't get me started about those stupid light bulbs.
 
subject: INTERRUPTEDEXCEPTION