Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Editors: please note these changes and the previous ones

...

Wiki Markup
The first condition can be relaxed when you can be sure that only one thread will ever update the value of the variable
Goetz 2006. However, code that relies on a
 \[[Goetz 06|AA. Java References#Goetz 06]\]. However, code that relies on a single-thread confinement is error-prone and difficult to maintain. This behavior is permissible under this guideline but not recommended.

Synchronizing the code makes it easier to reason about its behavior and is frequently more secure than simply using the volatile keyword. However, synchronization has a somewhat higher performance overhead and can result in thread contention and deadlocks when used excessively.
Declaring a variable volatile or correctly synchronizing the code guarantees that 64-bit primitive long and double variables are accessed atomically. (For more information on sharing those variables among multiple threads, see guideline “VNA05 VNA05-J. Ensure atomicity when reading and writing 64-bit values.")

Noncompliant Code Example (Non-Volatile Flag)

...