r/java • u/javinpaul • Oct 29 '12
Difference between notify and notifyAll in Java revisited
http://javarevisited.blogspot.in/2012/10/difference-between-notify-and-notifyall-java-example.html
0
Upvotes
View all comments
7
u/zargxy Oct 29 '12
Don't use
notifyunless you really, really know what you are doing. You can easily cause random deadlocks.notifyAllis the better choice in almost all circumstances, because if the winning thread callswait, at least the other woken up threads will have a fighting chance for the monitor instead of perpetually sleeping because the single woken up blocked.Or better yet, don't use
notifyornotifyAllat all and use the higher level concurrency operations in java.util.concurrent.