why wait/notify/notifyAll methods are not synchronized in java ?

后端 未结 7 1542
生来不讨喜
生来不讨喜 2020-12-05 10:20

in Java whenever we need to call wait/notify/notifyAll, we need to have access to object monitor (either through synchronized method or through synchronized block). So my q

7条回答
  •  北荒
    北荒 (楼主)
    2020-12-05 11:14

    My guess would be that the reason the synchronized block is required is that the use of wait() or notify() as the only action in a synchronized block is almost always a bug anyway.

    Findbugs even has a warning for this, which it calls a "naked notify".

提交回复
热议问题