/* * ======================================================================== * Consumer.java : A suclass of Thread that consumes and prints all numbers * from the cubbyhole object as soon as the Producer stores a number into the * same cubbyhole object. * * Adapted from : Campione M., Walrath K., Huml A., The Java Tutorial, 2000 * Modified by : Vasilios Lagakos March, 2001 * ========================================================================= */ public class Consumer extends Thread { private CubbyHole cubbyhole; // shared data private int number; public Consumer(CubbyHole c, int number) { cubbyhole = c; this.number = number; } public void run() { int value = 0; for (int i = 0; i < 10; i++) { value = cubbyhole.get(); // Accesses shared data System.out.println("Consumer #" + this.number + " got: " + value); } } }