ArrayBlockingQueue的问题
我用ArrayBlockingQueue实现producer和consumer的经典问题,伪代码大概如下:
Producer
while (!stop) {
queue.put(sth);
}
Consumer
while(!stop) {
queue.take();
}
但是,如果Producer突然挂了,而Consumer又刚好阻塞在 queue.take()这里,那么Consumer岂不永远等待下去?有什么办法可以让Producer通知Consumer呢?
我想过用interrupt(),但是比较麻烦。用notifyAll()又没有反应,真难搞。