Wednesday, 29 July 2015

BlockingQueue methods and implemetation


BlockingQueue

BlockingQueue is a Queue which supports flow control by introducing blocking (while underflow or overflow) along with storing the elements.

take() method of BlockingQueue will block if Queue is empty and thread trying to dequeue from an empty queue is blocked until some other thread inserts an item into the queue.

put() method of BlockingQueue will block if Queue is full and thread trying to enqueue an item in a full queue is blocked until some other thread makes space in the queue.

BlockingQueue
Implementation of BlockingQueue interface in java.util.concurrent package:
ArrayBlockingQueue
DelayQueue
LinkedBlockingDeque
LinkedBlockingQueue
PriorityBlockingQueue
SynchronousQueue

Operations of Blocking Queue

Throws exception
Special value
Blocks
Times out
Insert
add(e)
offer(e)
put(e)
offer(e, time, unit)
Remove
remove()
poll()
take()
poll(time, unit)
Examine
element()
peek()
not applicable
not applicable
Conditions
Queue is empty while removing, or Queue is full while adding element.
null or false
Block the thread until the operation can be accomplished.

Block the thread for a given maximum time limit before giving up.



No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...