What is BlockingQueue ?
A blocking queue is a queue that blocks when you try to dequeue an empty queue, or if you try to enqueue items in a full queue. A thread trying to dequeue from an empty queue is blocked until some other threads insert an item into the queue. A thread trying to enqueue an item in a full queue is blocked until some other threads make space available in the queue, either by dequeuing one or more items or clearing the queue completely, it means a queue that additionally 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 storing an element.
A BlockingQueue may be capacity bounded. At any given time it may have a remainingCapacity beyond which no additional elements can be put without blocking. A BlockingQueue without any intrinsic capacity constraints always reports a remaining capacity of Integer.MAX_VALUE. Continue reading “BlockingQueue in Java”