public void add() throws InterruptedException{
if(count>=10){
System.out.println(Thread.currentThread().getName()+":producter is enough");
this.wait();//满了wait
}else{
System.out.println("add prodecter:"+ ++count);
this.notifyAll();//所有线程可以继续
}
}
java.lang.IllegalMonitorStateException
at java.lang.Object.notifyAll(Native Method)
at com.czy.producterandconsume.Store.add(Store.java:20)
at com.czy.producterandconsume.Producter.run(Producter.java:14)
at java.lang.Thread.run(Unknown Source)
使用了wait、notify或者notifyAll方法,需要绑定synchronized,也就是说在方法前加上synchronized就行了