/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Resource r = new Resource();
Producer p = new Producer(r);
Consumer c = new Consumer(r);
Thread t1 = new Thread(p);
Thread t2 = new Thread(p);
Thread t3 = new Thread(c);
Thread t4 = new Thread(c);
t1.start();
t2.start();
t3.start();
t4.start();
}
}
现在我想当生产完第10个商品并将其消费掉,即当控制台打印出“Thread-x:消费了商品10”,就让整个程序终止,要怎么弄?作者: 杨_扬 时间: 2012-7-9 00:58
你的问题提的太早了,继续看视频,生产者,消费者下面就讲如何停止线程了作者: 游兴钟 时间: 2012-7-9 12:51
class Resource
{
private String name;
private int conut;
private boolean flag = false;
public synchronized void set(String name)
{
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Resource r = new Resource();
Producer p = new Producer(r);
Consumer c = new Consumer(r);
Thread t1 = new Thread(p);
Thread t2 = new Thread(p);
Thread t3 = new Thread(c);
Thread t4 = new Thread(c);
t1.start();
t2.start();
t3.start();
t4.start();
}
}
作者: 汤密奕 时间: 2012-7-9 13:04
achilles 发表于 2012-7-9 12:51
class Resource
{
private String name;