ArrayBlockingQueue

public void put(E e) throws InterruptedException {
    checkNotNull(e);
    final ReentrantLock lock = this.lock;
    lock.lockInterruptibly(); // 锁
    try {
        while (count == items.length)
            notFull.await(); // 阻塞
        enqueue(e);
    } finally {
        lock.unlock();
    }
}

public E take() throws InterruptedException {
    final ReentrantLock lock = this.lock;
    lock.lockInterruptibly(); // 锁
    try {
        while (count == 0)
            notEmpty.await(); // 阻塞
        return dequeue();
    } finally {
        lock.unlock();
    }
}

LinkedBlockingQueue


怒放的生命
22 声望1 粉丝

« 上一篇
unsafe类