Versions Compared

Key

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

...

This is because the thread that holds a lock on the nonfinal field object can modify its the field's value, allowing another thread that is blocked on the unmodified value to resume, at the same time, contending for the lock with a third thread that is blocked on the modified value. It is insecure to synchronize on a mutable field because this is equivalent to synchronizing on the field's contents. This is a mutual exclusion problem as opposed to the sharing issue discussed in the previous noncompliant code example.

...