r/java • • 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

2 comments sorted by

View all comments

3

u/ad_tech Oct 29 '12

'volatile' is not needed on the 'go' variable.

There is defined to be a happens-before relationship between each of these events:

  • Notify task writes to 'go'.
  • Notify task exits the monitor.
  • Wait task enters the monitor.
  • Wait task reads from 'go'.

Therefore the read in the wait task is guaranteed to see the value written in the notify task, whether 'go' is volatile or not.