Blocking Queues
Home ] Up ] What is MultiThreading? ] Threads & Thread Properties ] Thread Scheduling and Priority ] Types of Threads ] Monitors, Synchronization and Deadlocks ] Thread Coordination ] Communication Between Threads ] Threads and Thread Groups ] Explicit Locks ] Atomic Variables ] [ Blocking Queues ] Thread-Safe Collections ] Callables & Futures ] The Executor Framework ] Synchronizers ]

 

Example

 

A common need, when dealing with multiple threads, is for a thread-safe coordinated queue into which you can place items of work, and from which a pool of threads can pick up those items of work and process them.

This is such a common need that Java 5 (and beyond) now provides such a set of queues.

All these queues implement the interface java.util.concurrent.BlockingQueue, or java.util.concurrent.BlockingDeque (for a double-ended queue version).

The queues implemented in the package java.util.concurrent include:

  • ArrayBlockingQueue -- A bounded blocking queue backed by an array.
  • LinkedBlockingQueue -- An optionally-bounded blocking queue based on linked nodes.
  • LinkedBlockingDeque -- An optionally-bounded blocking deque based on linked nodes.
  • PriorityBlockingQueue -- An unbounded blocking queue that uses the same ordering rules as class PriorityQueue and supplies blocking retrieval operations.
  • DelayQueue -- An unbounded blocking queue of Delayed elements, in which an element can only be taken when its delay has expired.
 
The page was last updated February 19, 2008