...
Code Block | ||
---|---|---|
| ||
public final class CountBoxes implements Runnable { private static volatile int counter; // ... public synchronized void run() { counter++; // ... } // ... } |
The problem is that this lock is associated with each instance of the class and not with the class object itself. Consequently, threads constructed using different Runnable
instances may observe inconsistent values of the counter
.
...