IllegalMonitorStateException的原因和解决方法
源码
package xzk.chapter4.section5;
public class Eat {
public static void main(String[] args) {
Food f = new Food();
new Cook(f).start();
new Waiter(f).start();
}
static class Cook extends Thread{// 厨师类
private Food f;
public Cook(Food f){// 厨师的食物对象
this.f=f;
}
@Override
public void run() {
try {
for(int i = 0 ;i< 10;i++){// 制作10份食物,5份蒸饺5份拌面
if(i%2==0){
f.setNameAndPrice("蒸饺","7元");
}else {
f.setNameAndPrice("拌面","5元");
}
} } catch (InterruptedException e) {
e.printStackTrace();
}
}
}
static class Waiter extends Thread{// 服务员类
private Food f;