public synchronized Bun pop(){
if(index==0) {
try{
this.wait();
} catch(InterruptedException e) {
e.printStackTrace();
}
}
this.notify();
index--;
return arr[index];
}
public synchronized Bun pop(){
while(index==0) {
try{
this.wait();
} catch(InterruptedException e) {
e.printStackTrace();
}
}
this.notify();
index--;
return arr[index];
} 他们说用if会不安全,不过我怎么感觉他们都是一样啊,不都是抛出异常时跳出去了吗?
if(index==0) {
try{
this.wait();
} catch(InterruptedException e) {
e.printStackTrace();
}
}
this.notify();
index--;
return arr[index];
}
public synchronized Bun pop(){
while(index==0) {
try{
this.wait();
} catch(InterruptedException e) {
e.printStackTrace();
}
}
this.notify();
index--;
return arr[index];
} 他们说用if会不安全,不过我怎么感觉他们都是一样啊,不都是抛出异常时跳出去了吗?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货