【发布时间】:2013-02-23 06:19:54
【问题描述】:
public synchronized static int get() {
while(cheia()==false){
try{
wait();
}
catch(InterruptedException e){
}
}
if (fila[inicio] != 0) {
int retornaValor = fila[inicio];
fila[inicio] = 0;
inicio++;
if (inicio == size) {
inicio = 0;
}
notifyAll();
return retornaValor;
}
notifyAll();
return 0;
}
为什么 wait() 和 notifyAll() 在这段代码中没有运行?
IDE 说:方法 wait()(或 notifyAll)不是静态的?
你能帮帮我吗?
【问题讨论】:
-
您可以改用
ClassName.class.wait()和ClassName.class.notifyAll()。
标签: java multithreading wait producer-consumer notify