ArrayBlockingQueue
,在put
方法裏面,爲什麼在追上InterruptedException
後調用notFull.signal()
?當線程終止時,爲什麼它會發出'未滿'信號?爲什麼在捕獲InterruptedException之後ArrayBlockingQueue信號'未滿'?
從source:
public void put(E e) throws InterruptedException {
if (e == null) throw new NullPointerException();
final E[] items = this.items;
final ReentrantLock lock = this.lock;
lock.lockInterruptibly();
try {
try {
while (count == items.length)
notFull.await();
} catch (InterruptedException ie) {
notFull.signal(); // propagate to non-interrupted thread
throw ie;
}
insert(e);
} finally {
lock.unlock();
}
}
請注意,自打開JDK的[Java 7實現]以來,我使用Java 6進行了標記(http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7u40-b43/java/util /concurrent/ArrayBlockingQueue.java#ArrayBlockingQueue.put%28java.lang.Object%29)似乎已經改變。 –