Archive for February, 2010

The BLOCKING in BlockQueue

February 8, 2010 Leave a comment

One of the core abilities of any concurrent program is the ability for block for events. java.util.BlockingQueue is a good example of an interface which provides that ability.

Following is an example from an array implementation (java.util.ArrayBlockingQueue):

public E take() throws InterruptedException {
final ReentrantLock lock = this.lock;
try {
try {
while (count == 0)
} catch (InterruptedException ie) {
notEmpty.signal(); // propagate to non-interrupted thread
throw ie;
E x = extract();
return x;
} finally {

Categories: Java, Java Collections