Does a thread implicitly call notifyAll() , if other Threads are waiting on it?

这一生的挚爱 提交于 2019-11-29 16:03:08

Thread calls notifyAll upon termination in support of the join functionality. This is documented in the Javadoc for Thread#join:

This implementation uses a loop of this.wait calls conditioned on this.isAlive. As a thread terminates the this.notifyAll method is invoked. It is recommended that applications not use wait, notify, or notifyAll on Thread instances.

There are essentially two conclusions then:

  • If you want to wait until a Thread terminates, use join.
  • If you want to use wait otherwise, do not use a Thread instance as a monitor.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!