Object.wait
Class Overview | Class Members |
This Package |
All Packages
public final native void wait( long timeout ) throws InterruptedException
Parameters
- timeout
- the maximum time to wait in milliseconds.
Description
Waits to be notified by another thread of a change in this object.
The current thread must own this object's monitor. The thread
releases ownership of this monitor and waits until either of the
following two conditions has occurred:
- 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 timeout period, specified by the timeout
argument in milliseconds, has elapsed.
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.
Exceptions
IllegalArgumentException
if the value of timeout is
negative.
Exceptions
IllegalMonitorStateException
if the current thread is not
the owner of the object's monitor.
Exceptions
InterruptedException
if another thread has
interrupted this thread.
See Also
notify, notifyAll
public final void wait( long timeout,
int nanos ) throws InterruptedException
Parameters
- timeout
- the maximum time to wait in milliseconds.
- nano
- additional time, in nanoseconds range
0-999999.
Description
Waits to be notified by another thread of a change in this object.
This method is similar to the wait method of one
argument, but it allows finer control over the amount of time to
wait for a notification before giving up.
The current thread must own this object's monitor. The thread
releases ownership of this monitor and waits until either of the
following two conditions has occurred:
- 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 timeout period, specified by timeout
milliseconds plus nanos nanoseconds arguments, has
elapsed.
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.
Exceptions
IllegalArgumentException
if the value of timeout is
negative or the value of nanos is
not in the range 0-999999.
Exceptions
IllegalMonitorStateException
if the current thread is not
the owner of this object's monitor.
Exceptions
InterruptedException
if another thread has
interrupted this thread.
public final void wait() throws InterruptedException
Description
Waits to be notified by another thread of a change in this object.
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.
Exceptions
IllegalMonitorStateException
if the current thread is not
the owner of the object's monitor.
Exceptions
InterruptedException
if another thread has
interrupted this thread.
See Also
notify, notifyAll