System.out.println(Thread.currentThread().getName()+"消费者 --->"+this.name+this.name);
flag=false;
this.notifyAll();//唤醒所有处于冻结状态的线程
}
}
class Producer implements Runnable{
Resouce r;
public Producer(Resouce r){
this.r=r;
}
public void run(){
while(true){
r.produce("商品");
}
}
}
class Consumer1 implements Runnable{
private Resouce r;
public Consumer1(Resouce r){
this.r=r;
}
public void run(){
while(true){
r.consumer();
}
}
}
public class TestTc {
public static void main(String[] args) {
Resouce r = new Resouce ();
Producer p = new Producer (r);
Consumer1 c = new Consumer1 (r);
new Thread(p).start();
new Thread(c).start();