Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

CON00-J. Ensure visibility when accessing shared primitive variables

CON01-J. Do not assume Ensure that composite operations on shared variables are atomic

CON02-J. Always synchronize on the appropriate object

...

Declaring shared variables as volatile ensures visibility and limits reordering of accesses. Volatile accesses do not guarantee the atomicity of composite operations such as incrementing a variable. Consequently, volatile is not applicable in cases where the atomicity of composite operations must be guaranteed (see CON01-J. Do not assume Ensure that composite operations on shared variables are atomic).

Declaring variables as volatile establishes a happens-before relationship such that a write to the volatile variable is always seen by a subsequent read. Statements that occur before the write to the volatile field also happen-before the read of the volatile field.

...