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

前端 未结 1 1811
北荒
北荒 2020-12-21 13:46

First thing i think i should say is that i am not looking for a solution , this is hwk , but it runs correctly , what would help me greatly is come clarification..

相关标签:
1条回答
  • 2020-12-21 14:11

    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.
    0 讨论(0)
提交回复
热议问题