Back to photostream

BlockingDeque in Java

This tutorial covers BlockingDeque in Java, its implementation classes, methods, and example of using BlockingDeque.

Java BlockingDeque

BlockingDeque is an interface in Java that is part of the Collections framework and present in the java.util.concurrent package. It blocks the insertion operation when the deque is full and blocks removal operation when it is empty. Since it is a Deque, it supports the insertion and removal of elements from both ends.

 

Hierarchy

 

Implementation class of BlockingDeque

The class that implements the Java BlockingDeque interface is the LinkedBlockingDeque class. It internally has a LinkedList data structure representation. It may be bounded if we specify the capacity in the constructor else it points to Integer.MAX_VALUE.

BlockingDeque bq = new LinkedBlockingDeque();

Methods in Java BlockingDeque

Below are the methods of the BlockingDeque interface. It also imports the methods present in the Deque and Collections interface.

 

Java BlockingDeque Example

Now let us see various examples of the BlockingDeque methods in the below section.

Example: Insert elements

The below example shows how to insert elements using the various methods in the BlockingDeque in Java. The addFirst(), offerFirst(), putFirst() and push() inserts the elements at the beginning of the deque.

import java.util.concurrent.BlockingDeque;

import java.util.concurrent.LinkedBlockingDeque;

 

public

 

www.tutorialcup.com/java/blockingdeque-in-java.htm

14 views
0 faves
0 comments
Uploaded on October 2, 2021