class Produces {
private int NumOfProduces;
private boolean flag;
private Object object;
public synchronized void setNumOfproduces() {
NumOfProduces++;
System.out.println(Thread.currentThread().getName() + "生产了产品,产品数目为:"
+ NumOfProduces);
notify();
}
public synchronized void getNumOfproduces() {
if (NumOfProduces <= 0) {
try {
wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
NumOfProduces--;
System.out.println(Thread.currentThread().getName() + "消费了产品,剩余产品数目为:"
+ NumOfProduces);
}
}
getNumOfproduces和setNumOfproduces是同一个锁吗
|
|