...
Code Block | ||
---|---|---|
| ||
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.
...