Java Reference
In-Depth Information
All BlockingQueue implementations must be thread-safe, but it is not re-
quired (unless explicitly documented by an implementation) that the
bulk collection operations ( addAll , containsAll , retainAll ) are executed
atomically.
The following blocking queue implementations are provided:
ArrayBlockingQueue A bounded blocking queue backed by an array.
You construct one with a capacity and an optional fairness set-
ting. If the queue is fair then blocked threads are processed
in first-in-first-out order; otherwise, blocked threads can be un-
blocked in arbitrary order. The queue itself is ordered first-in-
first-out. It provides a weakly consistent iterator.
LinkedBlockingQueue An optionally bounded queue based on a
linked node implementation. The queue elements are ordered
first-in-first-out. It provides a weakly consistent iterator.
A linked queue implementation will typically provide greater
throughput than an array-based implementation when used con-
currently. This is due to the use of algorithms that allow the head
and tail to be locked independently. However, a linked queue im-
plementation may require allocation for each insertion and pro-
duce garbage on each removal, which can add significant over-
head. When the queue is used as a fixed size buffer that is con-
stantly filled by one set of threads and then drained by another,
this overhead is at its worst, and an array-based implementation
may perform better than a bounded linked queue. Moreover, in
the usage pattern described, the additional concurrency support
of the linked queue isn't used because each thread within a set
operates on the same end of the queue.
PriorityBlockingQueue An unbounded queue ordered the same way
as a PriorityQueue . This implementation adds thread safety and
the blocking retrieval operations. It provides an iterator that is
thread-safe but fail-fast.
SynchronousQueue A specialized blocking queue where each take
must wait for a put , and vice versa. A synchronous queue has no
 
Search WWH ::




Custom Search