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.
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
offer (E
o , long
timeout , TimeUnit
unit ) throws InterruptedException;
public E
poll (long
timeout , TimeUnit
unit ) throws InterruptedException;
public void
put (E
o ) throws InterruptedException;
public int
remainingCapacity ( );
public E
take ( ) throws InterruptedException;
// Methods Implementing Collection
public void
clear ( );
public boolean
contains (Object
o );
public java.util.Iterator<E>
iterator ( );
public boolean
remove (Object
o );
public int
size ( );
public Object[ ]
toArray ( );
public <T> T[ ]
toArray (T[ ]
a );
// Methods Implementing Queue
public E
peek ( );
public E
poll ( );
// Public Methods Overriding AbstractCollection
public String
toString ( );
}