FileDocCategorySizeDatePackage
Producer.javaAPI DocExample838Tue May 04 09:43:04 BST 2004com.oreilly.tiger.ch10

Producer

public class Producer extends Thread

Fields Summary
private BlockingQueue
q
private PrintStream
out
Constructors Summary
public Producer(BlockingQueue q, PrintStream out)

    setName("Producer");
    this.q = q;
    this.out = out;
  
Methods Summary
private java.lang.Stringproduce()

    while (true) {
      double r = Math.random();

      // Only goes forward 1/10 of the time
      if ((r*100) < 10) {
        String s = String.format("Inserted at %tc", new Date());
        return s;
      }
    }
  
public voidrun()

    try {
      while (true) {
        q.put(produce());
      }
    } catch (InterruptedException e) {
      out.printf("%s interrupted: %s", getName(), e.getMessage());
    }