Home  >  Q&A  >  body text

thread - [多线程]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里吗?

ringa_leeringa_lee2646 days ago340

reply all(1)I'll reply

  • 大家讲道理

    大家讲道理2017-04-18 10:27:32

    Elementary actions就是Object.wait, Object.notify, and Object.notifyAll,只有这三个操作能够影响到对象的wait set,当调用一个对象的wait方法,就是把当前线程添加到这个对象的wait set,notify会把wait set的线程删除一个,notifyAll会删除所有线程吧

    reply
    0
  • Cancelreply