Causes the current thread to wait until another thread invokes the method or the 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
method or the
- notify
method. The thread then waits until it can re-obtain ownership of the monitor and resumes execution.
- notifyAll
As in the one argument version, interrupts and spurious wakeups are possible, and this method should always be used in a loop:
- synchronized (obj) {
- while (<condition does not hold>) //为了防止虚假唤醒应该总是使用在循环中
- obj.wait();
- ... // Perform action appropriate to condition
- }
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.
来源: