Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: added a conrner case as exception

...

However, synchronization is a more secure alternative in situations where the volatile keyword or an java.util.concurrent.atomic.Atomic* field is inappropriate, such as if a variable's new value depends on its old value. Refer to CON01-J. Ensure that compound operations on shared variables are atomic for more information.

Exceptions

EX1: An array of class objects need not be made visible because class objects are created by the Virtual Machine and their initialization always precedes any subsequent use. JMM Mailing List

Risk Assessment

Failing to ensure visibility of shared primitive variables on accesses can lead to a thread seeing stale values of the variables.

...