}作者: 王陶成 时间: 2012-9-10 21:58
public class ProducerConsumerDemo {
public static void mian(String[] args) {//这里写错了。main()否则编译器找不到入口
Resource r = new Resource();
Resource.Producer pro = new Resource().new Producer(r);//你的Producer类定义的是内部类所以要通过外部类调用
Resource.Consumer con = new Resource().new Consumer(r);//同理
Thread t1 = new Thread(pro);
Thread t2 = new Thread(con);
t1.start();
t2.start();
}
}
class Resource {
private String name;
private int count = 1;
private boolean flag = false;