/*
 *  ========================================================================
 *  Producer.java : A suclass of Thread that generates and stores incrementing
 *  numbers into a cubbyhole object with random pauses in between each increment.  
 *  Also, each number generated by the Producer object is printed to the screen.
 *
 *  Adapted from : Campione M., Walrath K., Huml A., The Java Tutorial, 2000
 *  Modified by : Vasilios Lagakos                              March, 2001 
 *  =========================================================================
 */

public class Producer extends Thread {
    private CubbyHole cubbyhole; 	// shared data
    private int number;

    public Producer(CubbyHole c, int number) {
        cubbyhole = c;
        this.number = number;
    }

    public void run() {
        for (int i = 0; i < 10; i++) {
            cubbyhole.put(i);		// Accesses shared data
            System.out.println("Producer #" + this.number
                               + " put: " + i);
            try {
                sleep((int)(Math.random() * 100));
            } catch (InterruptedException e) { }
        }
    }
}
