FileDocCategorySizeDatePackage
ProdCons2.javaAPI DocExample2922Mon Apr 30 09:47:34 BST 2001None

ProdCons2

public class ProdCons2 extends Object

Fields Summary
protected LinkedList
list
Throughout the code, this is the object we synchronize on so this is also the object we wait() and notifyAll() on.
protected int
MAX
protected boolean
done
Constructors Summary
ProdCons2(int nP, int nC)

		for (int i=0; i<nP; i++)
			new Producer().start();
		for (int i=0; i<nC; i++)
			new Consumer().start();
	
Methods Summary
public static voidmain(java.lang.String[] args)


		// Start producers and consumers
		int numProducers = 2;
		int numConsumers = 2;
		ProdCons2 pc = new ProdCons2(numProducers, numConsumers);

		// Let it run for, say, 30 seconds
		Thread.sleep(30*1000); 

		// End of simulation - shut down gracefully
		synchronized(pc.list) {
			pc.done = true;
			pc.list.notifyAll(); // Wake up any waiters!
		}