Object notifyAll() 方法用于唤醒在该对象上等待的所有线程。
notifyAll() 方法跟 notify() 方法一样,区别在于 notifyAll() 方法唤醒在此对象监视器上等待的所有线程,notify() 方法是一个线程。
如果当前线程不是对象监视器的所有者,那么调用 notifyAll() 方法同样会发生 IllegalMonitorStateException 异常。
语法
public final void notifyAll()
参数
无 。
返回值
没有返回值。
实例
以下实例演示了 notifyAll() 方法的使用:
以上程序执行结果为:
List is empty... List is empty... Opening... New Element:'Hello!' notifyAll called! Closing... Waiting... Waiting... List is empty... Hello! Interrupted Exception!