Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: added missing bracket in code

...

Code Block
bgColor#ccccff
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.

...