Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: minor edit

Reading a shared primitive variable in one thread may not yield the value of the most recent write to the variable from another thread. Consequently, the thread may observe a stale value of a the shared variable. Visibility of the most recent update can be ensured by declaring the variable as volatile or correctly synchronizing the reads and writes to the variable.

...

Synchronization is a more secure alternative in situations where the volatile keyword or a 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 on compound operations.

Exceptions

CON00-EX1: Objects of type Class need not be made visible because they are created by the Virtual Machine and their initialization always precedes any subsequent use JMM Mailing List.

...