Name
ArrayBlockingQueue<E>
Synopsis
This BlockingQueue
implementation
uses an array to store queue elements. The internal array has a fixed
size that is specified when the queue is created, which means that
this is a bounded queue and the put( ) method
blocks when the queue has no more room.
ArrayBlockingQueue orders its elements on a
first-in, first-out (FIFO) basis. As with all
BlockingQueue implementations,
null elements are prohibited.
If you pass true as the second argument to the
ArrayBlockingQueue constructor, the queue enforces
a fairness policy for blocked threads: threads blocked in
put( ) or take( ) are
themselves queued in FIFO order, and the thread that has been waiting
the longest is served first. This prevents thread starvation but may
decrease overall throughput for the
ArrayBlockingQueue.

Figure 16-71. java.util.concurrent.ArrayBlockingQueue<E>
public class ArrayBlockingQueue<E> extends java.util.AbstractQueue<E> implements BlockingQueue<E>, Serializable { // Public Constructors public ArrayBlockingQueue(int capacity); public ArrayBlockingQueue(int capacity, boolean fair); public ArrayBlockingQueue(int capacity, boolean fair, java.util.Collection<? extends E> c); // Methods Implementing BlockingQueue public int drainTo(java.util.Collection<? super E> c); public int drainTo(java.util.Collection<? super E> c, int maxElements); public boolean offer(E o); public boolean ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access