public void run() { int value; for (int i = 0; i < 10; i++) { value = cubbyhole.get(); System.out.println("exercise.Consumer #" + this.number + " got: " + value); } }
public void run() { for (int i = 0; i < 10; i++) { cubbyhole.put(i); System.out.println("exercise.Producer #" + this.number + " put: " + i); try { sleep((int) (Math.random() * 100)); } catch (InterruptedException e) { } } }
public void run() { try { for (int i = 0; i < 10; i++) { cubbyhole.put(i); sleep((int) (Math.random() * 100)); } } catch (InterruptedException e) { } finally { System.out.println("Goodbye from Producer (" + Thread.currentThread().getName() + ")"); } }
public void run() { int value = 0; try { for (int i = 0; i < 10; i++) { value = cubbyhole.get(); sleep((int) (Math.random() * 100)); } } catch (InterruptedException e) { } System.out.println("Goodbye from Consumer (" + Thread.currentThread().getName() + ")"); }