https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#wait()
monitor锁
wait()
notify()
notifyAll()
总结
wait() 当前thread已经获取了对象的monitor锁, wait(), 释放monitor锁, 且等待被唤醒之后重新加入争夺monitor锁的队列
notify() 当前thread已经获取了对象的monitor锁, 释放monitor锁, 并唤醒一个等待的线程
notify() 当前thread已经获取了对象的monitor锁, 释放monitor锁, 并唤醒所有等待的线程
线程a先加入等待monitor,之后才能被notify唤醒,
先等待, 再被唤醒。
网友评论