...
Code Block | ||
---|---|---|
| ||
public class CountBoxes implements Runnable {
private static int counter;
// ...
private static final Object lock = new Object();
public void run() {
synchronized(lock) {
counter++;
// ...
}
}
// ...
}
|
There is no need to declare the counter
variable volatile when using synchronization.
...