Java BlockingDeque

Last modified on November 30th, 2014 by Joe.

BlockingDeque is an interface that extends Deque and BlockingQueue. It combines both the operations of Deque and BlockingQueue.

A Deque is a double ended queue. It is a linear collection of elements wherein elements can be inserted and removed from both the ends.

BlockingQueue is a queue that supports blocking operations for that will wait for the queue to become non-empty when retrieving element from it and wait for space to become available when inserting elements.

BlockingDeque is a double ended queue that supports blocking operations as well.

BlockingDeque Operations

Following are the four types of operations available for each operations insert, remove and get for both ends of the queue.

Following table illustrates the head based operations on the Dequeue

Throws exception Returns value Blocks Timed
Insert addFirst(e) offerFirst(e) putFirst(e) offerFirst(e, time, unit)
Remove removeFirst() pollFirst() takeFirst() pollFirst(time, unit)
Examine getFirst() peekFirst() not applicable not applicable

Following table illustrates the tail based operations on the Dequeue

Throws exception Returns value Blocks Timed
Insert addLast(e) offerLast(e) putLast(e) offerLast(e, time, unit)
Remove removeLast() pollLast() takeLast() pollLast(time, unit)
Examine getLast() peekLast() not applicable not applicable

BlockingDeque implementation in JDK

BlockingDeque is an interface. Either we should write our own implementation or use an existing implementation from JDK. LinkedBlockingDeque is an implementation of BlockingDeque available in JDK. In the next Java tutorial we will see about LinkedBlockingDeque in detail.

Comments on "Java BlockingDeque"

  1. […] This Java tutorial is to learn about the concurrent collection LinkedBlockingDeque. It is an optionally bounded blocking double ended queue. LinkedBlockingDeque is an implementation of the interface Java BlockingDeque. […]

Comments are closed for "Java BlockingDeque".