Java synchronization is doing auto notify on exit ? Is this expected?

后端 未结 2 1844
孤独总比滥情好
孤独总比滥情好 2020-12-21 04:34

Java Question :

Coming out of synchronization block automatically does notifyAll(). Is that the expected behavior?

I have tested it and it seems like 1. wh

2条回答
  •  再見小時候
    2020-12-21 05:01

    You shouldn't use a Thread object as a locking object. See more explanations in question Does java notify waiting threads implicitly?.

    Advertisement: Jon Skeet speaks there :) (This is a direct link to the answer in the above linked question.)

    There is also another question linked from a comment, now I'll make it more achievable: who and when notify the thread.wait() when thread.join() is called?

提交回复
热议问题