The Java BlockingQueue interface in the java.util.concurrent package is a queue which is thread safe. It supports operations that wait for the queue to become non-empty when retrieving an element, and wait for space to become available in the queue when inserting an element. BlockingQueue implementations are designed to be used primarily for produc...

Read More

ArrayBlockingQueue is a bounded BlockingQueue backed by an array. This queue orders elements in FIFO (first-in-first-out). The head of the queue is the element which has been on the queue for the longest time. The tail of the queue is that element that has been on the queue for the shortest time. New elements are added at the tail of the queue, and...

Read More

In this post we are going to present the producer consumer implementation using ArrayBlockingQueue class, which implements the BlockingQueue interface. The main reason to use the ArrayBlockingQueue class is that it is thread-safe, in the sense that it can be used concurrently between different threads without any risk. Moreover, it has a specific c...

Read More

The LinkedBlockingQueue class implements the BlockingQueue interface. Read the BlockingQueue for more information about the interface. The LinkedBlockingQueue is an optionally-bounded blocking queue based on linked nodes. This queue orders elements FIFO (first-in-first-out). The head of the queue is the element that has been on the queue for the lo...

Read More

1 . LinkedBlockingQueue: This is a LinkedList Implementation but Not Exactly JDK Implementation of LinkedList It uses static inner class Node to maintain Links between elements. Check the following Constructor for LinkedBlockingQueue. public LinkedBlockingQueue(int capacity) { if (capacity < = 0) throw new IllegalArgumentException(); this....

Read More

In this post we will discuss about DelayQueue and how to make use of DelayQueue class. DelayQueue is a special type of BlockingQueue which allows elements to be retrieved in order of their finishing delay times i.e. an element whose delay time finishes first is retrieved first from DelayQueue. The DelayQueue is backed by a heap. In  DelayQueue impl...

Read More

PriorityBlockingQueue was included in concurrent package from JDK 5 see here. It belongs to java.util.concurrent package. It is an unbounded blocking queue backed by a priority heap and implementation of BlockingQueue and it also contains the feature of PriorityQueue. PriorityBlockingQueue uses the ordering rule same as PriorityQueue and in additio...

Read More

CountDownLatch in Java is a synchronization tool that allows one or more threads to wait until one or more number of threads completed some operation. So there are 2 types of threads, Type 1 : One/more are waiting thread(s). Type 2 : Threads for which the Type 1 thread(s) is/are waiting for. Here the CountDownLatch is initialized with a count which...

Read More

Callable interface was added in Java 5 to achieve some limitation in existing Runnable interface. A Thread created by implementing the Runnable interface cannot returns a result when the thread terminates. As the return type of run() method in Runnable interface is void. To overcome this the Callable interface was introduced in Java where we can re...

Read More

FOLLOW US ON LinkedIn



Explore Tutu'rself