Java并发集合之LinkedBlockingQueue
1.LinkedBlockingQueue简单介绍
首先基于其名字Linked可知其为链表式结构,Blocking则表示其为可阻塞的,Queue则说明满足队列的特性(FIFO)。
/**
* An optionally-bounded {@linkplain BlockingQueue blocking queue} based on
* linked nodes.
* This queue orders elements FIFO (first-in-first-out).
* The <em>head</em> of the queue is that element that has been on the
* queue the longest time.
* The <em>tail</em> of the queue is that element that has been on the
* queue the shortest time. New elements
* are inserted at the tail of the queue, and the queue retrieval
* operations obtain elements at the head of the queue.
* Linked queues typically have higher throughput than array-based queues but
* less predictable performance in most concurrent applications.
*
* <p>The optional capacity bound constructor argument serves as a
* way to prevent excessive queue expansion. The capacity, if unspecified,
* is equal to {@link Integer#MAX_VALUE}. Linked nodes are
* dynamically created upon each insertion unless this would bring the
* queue above capacity.
*
* <p>This class and its iterator implement all of the
* <em>optional</em> methods of the {@link Collection} and {@link
* Iterator} interfaces.
*
* <p>This class is a member of the
* <a href="{@docRoot}/../technotes/guides/collections/index.html">
* Java Collections Framework</a>.
总结一下大概的意思是:
1.1.此队列是基于链表节点并且可指定大小。
1.2 此队列是中的元素是先进先出的(FIFO),首节点是最先进入队列的,尾节点是最后进入队列的。
1.3 在并发情况下链式队列比数组形式的对于通常都有更高的吞吐但是缺不可预估其性能。
1.4 在构造LinkedList的时候可以传入队列的最大长度,如果不传入的话则队列的最大长度就为Integer.Max_Value(2的31次方-1)(由次可见LinkedList其实有最大长度)。
2.关系图
3.构造函数
4.添加元素
5.删除元素
6.应用场景

浙公网安备 33010602011771号