Java-java.util.concurrent.LinkedBlockingQueue
原创
©著作权归作者所有:来自51CTO博客作者文天大人的原创作品,请联系作者获取转载授权,否则将追究法律责任
在了解LinkedBlockingQueue之前,请先了解GuardedBlocks
public void put(E e) throws InterruptedException {
if (e == null) {
throw new NullPointerException();
}
final int c;
final Node<E> node = new Node<E>(e);
final ReentrantLock putLock = this.putLock;
final AtomicInteger count = this.count;
putLock.lockInterruptibly();
try {
while (count.get() == capacity) {
notFull.await();
}
enqueue(node);
c = count.getAndIncrement();
if (c + 1 < capacity)
notFull.signal();
} finally {
putLock.unlock();
}
if (c == 0)
signalNotEmpty();
}