当前位置 : 主页 > 编程语言 > java >

Java-java.util.concurrent.LinkedBlockingQueue

来源:互联网 收集:自由互联 发布时间:2022-07-13
在了解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 Reentrant


在了解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();
}


上一篇:Java-虚拟机-类加载(装载连接初始化)
下一篇:没有了
网友评论