Source of Producer.java


  1: public class Producer extends Thread {
  2: 
  3:     protected BoundedQueue queue;
  4:     protected int n;
  5: 
  6:     public Producer(BoundedQueue queue, int n) {
  7:         this.queue = queue;
  8:         this.n = n;
  9:     }
 10: 
 11:     public void run() {
 12:         for (int i = 0; i < n; i++) {
 13:             queue.put(new Integer(i));
 14:             System.out.println("produce: " + i);
 15:             try {
 16:                sleep((int)(Math.random() * 100));
 17:             }  catch (InterruptedException e) {}
 18:         }
 19:     }
 20: }