Versions Compared

Key

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

...

Code Block
bgColor#FFCCCC
class CountHits {
  private static int counter;
  
  public void incrementCounter() {
    counter++;
  }
}

ConsequentlyIt relies on clients to externally synchronize the object and states so in the documentation. However, there is no guarantee that all unrelated clients will externally synchronize accessesdo this.

Compliant Solution

This compliant solution internally synchronizes the counter field and does not depend on any external synchronization.

...