Home  >  Forum  >  Core Java
Post New Query

How does BlockingQueue work in java internally

joined on
November 09,2013
Asked on March 23,2014
Hi All,
Please explain  
How does BlockingQueue work in java internally?

joined on
March 14,2013
Replied on March 23,2014

Check the java doc.
BlockingQueue is an interface and there are many implementation of the it.
One of this implementation is ArrayBlockingQueue. The main feature of  BlockingQueue is it provides such methods that will wait to insert and fetch element from the queue.  To understand ,  how does ArrayBlockingQueue do, we need to know ReetrantLock and Condition of java concurrent API.  

1. Get the ReetrantLock instance.
2. Call a method lockInterruptibly()  to get lock. It returns lock if no thread has locked otherwise becomes idle and is invoked once lock is available.
3. Once lock is obtained, wait for getting space in ArrayBlockingQueue with the help of Condition await() method, once it gets space, insert the element.

joined on
March 14,2013
Replied on March 23,2014

Find the link for more interview question of concurrent API.

Write Answer

Copyright ©2017 concretepage.com, all rights reserved |Privacy Policy | Contact Us