Home >Java >javaTutorial >What are the operating methods of java blocking queue?

What are the operating methods of java blocking queue?

WBOY
WBOYforward
2023-04-18 09:55:081538browse

1. Support blocking insertion method. When the queue is full, the queue will block the thread inserting elements until the queue is full.

2. Supports the blocking removal method. When the queue is empty, the thread that obtains the element will wait for the queue to become non-empty.

Example

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

The above is the detailed content of What are the operating methods of java blocking queue?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete