How notify method works

后端 未结 1 960
栀梦
栀梦 2021-01-21 16:46

As per the javadoc notify Wakes up a single thread that is waiting on this object\'s monitor. If any threads are waiting on this object, one of them is chosen to be awakened. Th

1条回答
  •  北荒
    北荒 (楼主)
    2021-01-21 17:23

    It does not send it to the first thread, but to any waiting thread (but only one thread).

    You should read the javadoc more carefully.

    Signal is also possibly a bad name for it, 'notify' is better. The actual implementation of the mechanism is transparent to the Java programmer, and the technical implementation should not be necessary for you to know.... unless you have an interest in Java internals, and then I suggest you inspect the OpenJDK source code.

    0 讨论(0)
提交回复
热议问题