Java BlockingQueue

BlockingQueue is an interface in java, which is useful for picking and inserting the elements into the Queue. Which is a thread safe meaning that multiple threads can insert and pick the elements at a time and also BlockingQueue have the capability of blocking threads while inserting and picking the elements from the Queue.

BlockingQueue inserting and picking can be done in four different ways and the following are the list of methods supported by the BlockingQueue.


Operation throws Exception Special Value Blocks Times Out
Insert add(e) offer(e) put(e) offer(e, time, unit)
Remove remove(Object e) poll() take() poll(time, unit)
Examine element() peek() N/A N/A

Any operation in the BlockingQueue can be performed in four ways except the examine operation. Lets what is four operations are there.

Insert Operation

Remove Operation

Examine Operation