How does BlockingQueue work in java internally




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





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.




Replied on March 23, 2014
Find the link for more interview question of concurrent API.
http://www.concretepage.com/interview/java-interview/interview-questions-core-java-concurrent-api


Write Answer











©2024 concretepage.com | Privacy Policy | Contact Us