Versions Compared

Key

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

During initialization of a shared object, the object must only be accessible to the thread constructing it. However, the object can be safely published (that is, made visible to other threads) once it is initialized. The Java Memory Model (JMM) allows multiple threads to observe the object after its initialization has begun, but before it has concluded. Consequently, it is important to ensure that a partially initialized object is not published.

This guideline differs from other guidelines in that it prohibits publishing a reference to a partially initialized member object instance before initialization completes while CON14-J. Do not let the "this" reference escape during object construction refers to prohibits the this reference of the current object from escaping.

Noncompliant Code Example

...