[多线程]Java中每个object的wait set是被谁操作的?
官方文档里有一段话:
Every object, in addition to having an associated monitor, has an associated wait set. A wait set is a set of threads.
When an object is first created, its wait set is empty. Elementary actions that add threads to and remove threads from wait sets are atomic. Wait sets are manipulated solely through the methods Object.wait, Object.notify, and Object.notifyAll.
我的疑问是,上面说的操作wait set的Elementary actions是什么操作的?还有,比如我的一个service excute了多个runnable对象,所有的线程都自动地互相添加到每个object的wait set里吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Elementary actions就是Object.wait, Object.notify, and Object.notifyAll,只有这三个操作能够影响到对象的wait set,当调用一个对象的wait方法,就是把当前线程添加到这个对象的wait set,notify会把wait set的线程删除一个,notifyAll会删除所有线程吧