LinkedBlockingQueue是一个基于已链接节点的、范围任意的blockingqueue的实现<wbr style="line-height:25px">。<br style="line-height:25px"><span style="color:#000080; line-height:25px">此队列按FIFO(先进先出)排序元素。队列的头部是在队列中时间最长的元素。队列的尾部是在队列中时间最短的元素。<br style="line-height:25px"> 新元素插入到队列的尾部,并且队列检索操作会获得位于队列头部的元素。链接队列的吞吐量通常要高于基于数组的队列,<br style="line-height:25px"> 但是在大多数并发应用程序中,其可预知的性能要低。<br style="line-height:25px"> 可选的容量范围构造方法参数作为防止队列过度扩展的一种方法。<br style="line-height:25px"> 如果未指定容量,则它等于</span><span style="color:#0000ff; line-height:25px">Integer.MAX_VALUE</span><span style="color:#000080; line-height:25px">。除非插入节点会使队列超出容量,否则每次插入后会动态地创建链接节点。</span><br style="line-height:25px"><span style="line-height:25px">构造函数</span></wbr>
关于LinkedBlockingQueue的使用请参考《
ArrayBlockingQueue》和《
BlockingQueue》
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
<nobr style="line-height:21px"></nobr> | <nobr style="line-height:21px"><span style="line-height:21px; margin-right:2px"><a rel="nofollow" href="http://developer.android.com/reference/java/util/concurrent/LinkedBlockingDeque.html#LinkedBlockingDeque()" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">LinkedBlockingDeque</a></span>()</nobr>
Creates a
LinkedBlockingDeque with a capacity of
MAX_VALUE .
| ||||||||||
<nobr style="line-height:21px"></nobr> | <nobr style="line-height:21px"><span style="line-height:21px; margin-right:2px"><a rel="nofollow" href="http://developer.android.com/reference/java/util/concurrent/LinkedBlockingDeque.html#LinkedBlockingDeque(int)" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">LinkedBlockingDeque</a></span>(int capacity)</nobr>
Creates a
LinkedBlockingDeque with the given (fixed) capacity.
| ||||||||||
<nobr style="line-height:21px"></nobr> | <nobr style="line-height:21px"><span style="line-height:21px; margin-right:2px"><a rel="nofollow" href="http://developer.android.com/reference/java/util/concurrent/LinkedBlockingDeque.html#LinkedBlockingDeque(java.util.Collection<?%20extends%20E>)" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">LinkedBlockingDeque</a></span>(<a rel="nofollow" href="http://developer.android.com/reference/java/util/Collection.html" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">Collection</a><?extendsE> c)</nobr>
Creates a
LinkedBlockingDeque with a capacity of
MAX_VALUE , initially containing the elements of the given collection, added in traversal order of the collection's iterator.
|
<wbr style="line-height:25px">注意1</wbr><wbr style="line-height:25px">:容量范围可以在构造方法参数中指定作为防止队列过度扩展。如果未指定容量,则它等于Integer.MAX_VALUE<br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">注意2</wbr></span><wbr style="line-height:25px">:它是线程安全的,是线程阻塞的。<br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">注意3</wbr></span><wbr style="line-height:25px">:不接受null元素<br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">注意4</wbr></span><wbr style="line-height:25px">:它实现了BlockingQueue接口。关于BlockingQueue,请参考《<span style="line-height:24px; font-weight:bold; white-space:nowrap"><a title="阅读全文" target="_blank" href="http://hubingforever.blog.163.com/blog/static/17104057920107415915820/" style="color:rgb(207,121,28); line-height:25px; text-decoration:none">BlockingQueue</a></span></wbr></wbr></wbr></wbr>
》
<wbr style="line-height:25px">注意5</wbr><wbr style="line-height:25px">:它没有线程ArrayBlockingQueue那样的公平性设置。为什么这样设计呢?puzzle.<br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">注意6</wbr></span><wbr style="line-height:25px">:此类及其迭代器实现了Collection和Iterator接口的所有可选方法。</wbr></wbr><wbr style="line-height:25px"><div style="line-height:25px"><span style="line-height:25px; font-family:Arial,Helvetica,simsun,u5b8bu4f53"><span style="line-height:25px">注意7</span>:在JDK5/6中,LinkedBlockingQueue和ArrayBlocingQueue等对象的poll(longtimeout,TimeUnitunit)存在内存泄露<br style="line-height:25px"> Leak的对象是AbstractQueuedSynchronizer.Node,<br style="line-height:25px"> 据称JDK5会在Update12里Fix,JDK6会在Update2里Fix。<br style="line-height:25px"> 更加详细参考<a target="_blank" rel="nofollow" href="http://sesame.javaeye.com/blog/428026" style="color:rgb(207,121,28); line-height:25px; text-decoration:none">http://sesame.javaeye.com/blog/428026</a><wbr style="line-height:25px">和<a target="_blank" rel="nofollow" href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=2143840" style="color:rgb(207,121,28); line-height:25px; text-decoration:none">http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=2143840</a><wbr style="line-height:25px"></wbr></wbr></span></div> <br style="line-height:25px"></wbr>
<wbr style="line-height:25px">注意5</wbr><wbr style="line-height:25px">:它没有线程ArrayBlockingQueue那样的公平性设置。为什么这样设计呢?puzzle.<br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">注意6</wbr></span><wbr style="line-height:25px">:此类及其迭代器实现了Collection和Iterator接口的所有可选方法。</wbr></wbr><wbr style="line-height:25px"><div style="line-height:25px"><span style="line-height:25px; font-family:Arial,Helvetica,simsun,u5b8bu4f53"><span style="line-height:25px">注意7</span>:在JDK5/6中,LinkedBlockingQueue和ArrayBlocingQueue等对象的poll(longtimeout,TimeUnitunit)存在内存泄露<br style="line-height:25px"> Leak的对象是AbstractQueuedSynchronizer.Node,<br style="line-height:25px"> 据称JDK5会在Update12里Fix,JDK6会在Update2里Fix。<br style="line-height:25px"> 更加详细参考<a target="_blank" rel="nofollow" href="http://sesame.javaeye.com/blog/428026" style="color:rgb(207,121,28); line-height:25px; text-decoration:none">http://sesame.javaeye.com/blog/428026</a><wbr style="line-height:25px">和<a target="_blank" rel="nofollow" href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=2143840" style="color:rgb(207,121,28); line-height:25px; text-decoration:none">http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=2143840</a><wbr style="line-height:25px"></wbr></wbr></span></div> <br style="line-height:25px"></wbr>