Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: added blurb that private object locks are only for public (or accessible) objects

...

This idiom can also be suitably used by classes designed for inheritance. If a superclass thread requests a lock on the class object's monitor, a subclass thread can interfere with its operation. Refer to the guideline CON02-J. Always synchronize on the appropriate object for more details.

This idiom is only useful for objects that may be accessible to hostile code. A private object gains no benefits from synchronizing on a private lock object, rather than synchronizing on its own intrinsic lock.

Noncompliant Code Example

...