1。未同步情况下的生产者/消费者关系。







//生产者的线程
public class Product extends Thread
...{
private Buffer sharedLocation;
public Product(Buffer shared)
...{
super("Product");
sharedLocation = shared;
}
public void run()
...{
for(int i=1;i<=4;i++)
...{
try...{
Thread.sleep((int)(Math.random() * 3001));
sharedLocation.set(i);
}catch(InterruptedException exception)...{
exception.printsStackTrace;
}
}
System.err.println(getName() + "done producing." + " Termination" + getName() + ".");
}
}















































































