标签:tst notify produce nts void product not rod sync
生产者 if(this.product>MAX_PRODUCT){
try{
wait();
}catch(InterruptedException e){
e.printStackTrace();
}
return;
}
this.product++;//如果没有大于生产最大上限,则进行生产
notifyAll();//通知消费者取出产品
}
消费者
public void synchronized resume(){
if(this.product<MIN_PRODUCT){//小于最小产品量
try{
wait();
}catch(InterruptedException e){
e.printStackTrace();
}
return;
}
this.product--;//如果没有大于生产最大上限,则进行生产
notifyAll();//通知消费者取出产品
}
标签:tst notify produce nts void product not rod sync
原文地址:http://blog.51cto.com/13919712/2160905