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 ...
Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.