本帖最后由 哈达洋 于 2014-10-17 23:05 编辑
wait()方法一执行,就会释放锁,这恰恰也是和sleep()方法的一个区别所在,sleep()方法是不释放锁的。下面是源代码中的部分注释:
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 {@code notify} method or the
* {@code notifyAll} method.
|