Home >Java >javaTutorial >What are the operating methods of java blocking queue?
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!