Java Reference
In-Depth Information
14.5. Details of Waiting and Notification
There are three forms of wait and two forms of notification. All of them
are methods in the Object class, and all are final so that their behavior
cannot be changed:
public final void wait(long timeout) tHRows InterruptedException
The current thread waits until one of four things happens: no-
tify is invoked on this object and this thread is selected to
be runnable; notifyAll is invoked on this object; the speci-
fied timeout expires; or the thread has its interrupt method in-
voked. timeout is in milliseconds. If timeout is zero, the wait will
not time out but will wait indefinitely for notification. During
the wait the lock of the object is released and is automatically
reacquired before wait completesregardless of how or why wait
completes. An InterruptedException is thrown if the wait com-
pletes because the thread is interrupted.
public final void wait(long timeout, int nanos) tHRows InterruptedEx-
ception
A finer-grained wait , with the time-out interval as the sum of
the two parameters: timeout in milliseconds and nanos in nano-
seconds, in the range 0999999).
public final void wait() throws InterruptedException
Equivalent to wait(0) .
public final void notifyAll()
Notifies all the threads waiting for a condition to change.
Threads will return from the wait invocation once they can
reacquire the object's lock.
 
Search WWH ::




Custom Search