Sponsored Links

Ad by Google
After completion of Hibernate Tutorial and Hibernate Interview Question, I am started with java 5's one of the excellent feature called BlockingQueue. After java 5, java 7 and java 8 introduced very power full features. You can read more about Java 7 features.
In this tutorial, I will explain, what is BlockingQueue and what are the implementations of BlockingQueue.
The java.util.concurrent.BlockingQueue is an interface extends Queue interface and Queue extends Collection interface.
That means, BlockingQueue act as a Queue and supports all the methods of Collection, Queue is based on FIFO(First-In-First-Out) data structure, which says the element inserted first into the queue will retrieved first from the queue like Car reached first at petrol pump will get fuel first.
The BlockingQueue act as a Queue and additionally support  the operations that wait for the queue to become non-empty while retrieving and element from the queue, and same way wait for the space to become available in the queue when putting element into the queue. BlockingQueue does not allow null element into the queue, If trying to adding null element in BlockingQueue, it will throws nullpointer exception.
To achieve the above said wait and notify functionality in queue, BlockingQueue introduced four different flavors of methods to insert elements into the queue and same way four different methods to remove the elements from the queue. The BlockingQueue is thread safe and designed to be used primarily for producer-consumer queues.

Remove element from the Queue -

Implementation of BlockingQueue

Below are the different implementation of BlockingQueue interface -
  1. ArrayBlockingQueue - Since Java 1.5
  2. LinkedBlockingDeque - Since Java 1.6
  3. LinkedBlockingQueue - Since Java 1.5
  4. LinkedTransferQueue - Since Java 1.7
  5. PriorityBlockingQueue - Since Java 1.5
  6. SynchronousQueue - Since Java 1.5
  7. DelayQueue - Since Java 1.5

That's it :)
Sponsored Links


Post a Comment