Versions Compared

Key

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

...

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 synchronization is used.

...