Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: added CON04-J ref

...

While this is an acceptable compliant solution, intrinsic locks cause threads to block and may introduce contention. On the other hand, volatile-qualified shared variables do not block. Excessive synchronization can also make the program prone to deadlock. CON04-J. Synchronize using an internal private final lock object mitigates many of these problems by encapsulating the lock in a private field.

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 current value. Refer to CON01-J. Ensure that compound operations on shared variables are atomic for more information.

...