(1)wait函数
调用wait方法后,线程被阻塞挂起,直到其他线程调用了notify()或notifyAll()后返回,其他线程调用了interrupt()方法,抛出InterruptedException异常返回。如果调用wait()方法前没有获取到该对象的监视器锁,则会抛出IllegalMonitorException异常
synchronized(queue){
//防止虚假唤醒,对queue资源进行循环检测,直到满足条件后才执行后面的add操作
while(queue.size() == MAX_SIZE){
try{
queue.wait();
}catch(Exception e){
e.printStackTrace();
}
}
queue.add(ele);
queue.notifyAll();
}
synchronized(queue){
//防止虚假唤醒,对queue资源进行循环检测,直到满足条件后才执行后面的add操作
while(! queue.isEmpty()){
try{
queue.wait();
}catch(Exception e){
e.printStackTrace();
}
&nbs