读书人

BoneCP源码BoneCP中应用的队列

发布时间: 2013-04-02 12:35:26 作者: rapoo

BoneCP源码——BoneCP中使用的队列
TransferQueue<ConnectionHandle> connectionHandles;public interface TransferQueue<E> extends BlockingQueue<E> {}

if (config.getMaxConnectionsPerPartition() == config.getMinConnectionsPerPartition()){// if we have a pool that we don't want resized, make it even faster by ignoring// the size constraints.connectionHandles = queueLIFO ? new LIFOQueue<ConnectionHandle>() :  new LinkedTransferQueue<ConnectionHandle>();} else {connectionHandles = queueLIFO ? new LIFOQueue<ConnectionHandle>(this.config.getMaxConnectionsPerPartition()) : new BoundedLinkedTransferQueue<ConnectionHandle>(this.config.getMaxConnectionsPerPartition());}

?如果设置了queueLIFO,则使用LIFOQueue队列,该队列继承LinkedBlockingDeque:

public class LIFOQueue<E> extends LinkedBlockingDeque<E> implements TransferQueue<E>{}

static final class Node<E> { E item; Node<E> prev; Node<E> next; Node(E x) { item = x; } }

/** Maximum number of items in the deque */ private final int capacity; public LinkedBlockingDeque() { this(Integer.MAX_VALUE); } public LinkedBlockingDeque(int capacity) { if (capacity <= 0) throw new IllegalArgumentException(); this.capacity = capacity; }

/** Main lock guarding all access */ final ReentrantLock lock = new ReentrantLock(); /** Condition for waiting takes */ private final Condition notEmpty = lock.newCondition(); /** Condition for waiting puts */ private final Condition notFull = lock.newCondition();

/** No of elements in queue. */private AtomicInteger size = new AtomicInteger();/** bound of queue. */private final int maxQueueSize;/** Main lock guarding all access */private final ReentrantLock lock = new ReentrantLock();public BoundedLinkedTransferQueue(int maxQueueSize){this.maxQueueSize = maxQueueSize;}

?

?

?

读书人网 >开源软件

热点推荐