您好我是编程的新手,我正在尝试做一个简单的生产者 - 消费者问题..但不幸的是我的线程永远等待..notify不工作..任何想法?:/
public synchronized void order() throws Exception{
System.out.println("User "+name+" requests:\n"+"cherries=" + cherries);
while(checkValues()==true){
System.out.println(name+" waiting");
wait();
}
notify();
Update();
store.toString();
System.out.println(name+" gets resources ");
Thread.sleep(5000);
}
Run Code Online (Sandbox Code Playgroud)