Versions Compared

Key

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

...

Code Block
bgColor#FFcccc
class PackBoxCountBoxes implements Runnable {
  static volatile int lengthcounter;
  // ...

  Object lock = new Object();    

  public void run() {
    synchronized(lock) {
      lengthcounter++; // Dimensions after packing the box	 
      // ... 
    } 
  }

  public static void main(String[] args) {
    Runnable r1 = new Box();
    Thread t1 = new Thread(r1);
    Runnable r2 = new Box();
    Thread t2 = new Thread(r2);
    t1.start();
    t2.start();
  }
}

...

Code Block
bgColor#ccccff
class PackBoxCountBoxes implements Runnable {
  static volatile int lengthcounter;
  // ...

  static Object lock = new Object();    
  // ...
}

...