Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: please review

...

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.

The guideline CON04-J. Synchronize using an internal private final lock object reduces the likelihood of misuse by ensuring that untrusted callers cannot access the lock object.

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.

...