org.apache.maven.surefire.util.internal
Class TwoThreadBlockingQueue

java.lang.Object
  extended by org.apache.maven.surefire.util.internal.TwoThreadBlockingQueue
All Implemented Interfaces:
BlockingQueue

public class TwoThreadBlockingQueue
extends Object
implements BlockingQueue

A producer/consumer queue that is optimized for *one* producer thread and *one* consumer thread, and solely optimized for efficient inserts by the producer, minimizing producer locking for hand-off to a second consumer. The producer can actually come in on different threads (because lastInserted is volatile), but can/will lose items if they arrive concurrently. Take only supports a single client. This runs like crazy, but is not the most garbage friendly around. TwoThreadBlockingQueue insert 5000000 elements in = 52ms LinkedBlockingQueue insert 5000000 elements in = 179ms LikedBlockingDeque insert 5000000 elements in = 114ms ArrayList insert 5000000 elements in = 18ms (sized at correct size from start)

Author:
Kristian Rosenvold

Field Summary
static Object poison
           
 
Constructor Summary
TwoThreadBlockingQueue()
           
 
Method Summary
 void add(Object object)
           
 Object take()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

poison

public static final Object poison
Constructor Detail

TwoThreadBlockingQueue

public TwoThreadBlockingQueue()
Method Detail

add

public void add(Object object)
Specified by:
add in interface BlockingQueue

take

public Object take()
            throws InterruptedException
Specified by:
take in interface BlockingQueue
Throws:
InterruptedException


Copyright © 2004-2011 The Apache Software Foundation. All Rights Reserved.