...
Code Block | ||
---|---|---|
| ||
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 | ||
---|---|---|
| ||
class PackBoxCountBoxes implements Runnable { static volatile int lengthcounter; // ... static Object lock = new Object(); // ... } |
...