码迷,mamicode.com
首页 > 其他好文 > 详细

Object.notifyAll()

时间:2015-05-07 14:03:01      阅读:100      评论:0      收藏:0      [点我收藏+]

标签:

技术分享 void java.lang.Object.notifyAll()

 

Causes all threads which are waiting on this object‘s monitor (by means of calling one of the wait() methods) to be woken up. The threads will not run immediately. The thread that called notify() has to release the object‘s monitor first. Also, the threads still have to compete against other threads that try to synchronize on the same object.

This method can only be invoked by a thread which owns this object‘s monitor. A thread becomes owner of an object‘s monitor

  • by executing a synchronized method of that object;
  • by executing the body of a synchronized statement that synchronizes on the object;
  • by executing a synchronized static method if the object is of type Class.
Throws:
IllegalMonitorStateException - if the thread calling this method is not the owner of this object‘s monitor.
See Also:
notify
wait()
wait(long)
wait(long, int)
java.lang.Thread
作用:唤醒所有在object对象上调用wait()方法的线程,线程不一定会立即执行。调用了notify()方法的线程会首先释放object锁,而且线程仍然需要和其他线程竞争来同步同一个对象。此方法只能唤醒拥有对象锁的线程。一个对象要拥有一个对象锁,可以通过下面三个方法:
1.  执行此对象的一个同步方法
2.  执行同步此对象的方法块
3.  如果对象是Class类型,执行一个同步静态方法
抛出异常:IllegalMonitorStateException    如果调用notifyAll()的线程不是锁的拥有者

Object.notifyAll()

标签:

原文地址:http://www.cnblogs.com/luow/p/4484655.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!