LinkedBlockingQueueE(示例,出错代码)
java.util.concurrent
类 LinkedBlockingQueue<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractQueue<E>
java.util.concurrent.LinkedBlockingQueue<E>
- 类型参数:
E
- the type of elements held in this collection
- 所有已实现的接口:
- Serializable, Iterable<E>, Collection<E>, BlockingQueue<E>, Queue<E>
public class LinkedBlockingQueue<E>extends AbstractQueue<E>implements BlockingQueue<E>, Serializable
An optionally-bounded blocking queue based on linked nodes. This queue orders elements FIFO (first-in-first-out). The head of the queue is that element that has been on the queue the longest time. The tail 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.
The optional capacity bound constructor argument serves as a way to prevent excessive queue expansion. The capacity, if unspecified, is equal to Integer.MAX_VALUE. Linked nodes are dynamically created upon each insertion unless this would bring the queue above capacity.
This class implements all of the optional methods of the Collection and Iterator interfaces.
- 从以下版本开始:
- 1.5
- 作者:
- Doug Lea
- 另请参见:
- 序列化表格
构造方法摘要 | |
---|---|
LinkedBlockingQueue() Creates a LinkedBlockingQueue with a capacity of Integer.MAX_VALUE. |
|
LinkedBlockingQueue(Collection<? extends E> c) Creates a LinkedBlockingQueue with a capacity of Integer.MAX_VALUE, initially containing the elements of the given collection, added in traversal order of the collection's iterator. |
|
LinkedBlockingQueue(int capacity) Creates a LinkedBlockingQueue with the given (fixed) capacity. |
方法摘要 | ||
---|---|---|
void |
clear() Removes all elements of the queue, leaving it empty. |
|
int |
drainTo(Collection<? super E> c) Removes all available elements from this queue and adds them into the given collection. |
|
int |
drainTo(Collection<? super E> c, int maxElements) Removes at most the given number of available elements from this queue and adds them into the given collection. |
|
Iterator<E> |
iterator() Returns an iterator over the elements in this queue in proper sequence. |
|
boolean |
offer(E o) Inserts the specified element at the tail of this queue if possible, returning immediately if this queue is full. |
|
boolean |
offer(E o, long timeout, TimeUnit unit) Inserts the specified element at the tail of this queue, waiting if necessary up to the specified wait time for space to become available. |
|
E |
peek() Gets but does not remove the element at the head of the queue. |
|
E |
poll() Gets and removes the element at the head of the queue, or returns null if there is no element in the queue. |
|
E |
poll(long timeout, TimeUnit unit) Retrieves and removes the head of this queue, waiting if necessary up to the specified wait time if no elements are present on this queue. |
|
void |
put(E o) Adds the specified element to the tail of this queue, waiting if necessary for space to become available. |
|
int |
remainingCapacity() Returns the number of elements that this queue can ideally (in the absence of memory or resource constraints) accept without blocking. |
|
boolean |
remove(Object o) Removes one instance of the specified object from this Collection if one is contained (optional). |
|
int |
size() Returns the number of elements in this queue. |
|
E |
take() Retrieves and removes the head of this queue, waiting if no elements are present on this queue. |
|
Object[] |
toArray() Returns a new array containing all elements contained in this Collection . |
|
|
toArray(T[] a) Returns an array containing all elements contained in this Collection . |
|
String |
toString() Returns the string representation of this Collection . |
从类 java.util.AbstractQueue 继承的方法 |
---|
add, addAll, element, remove |
从类 java.util.AbstractCollection 继承的方法 |
---|
contains, containsAll, isEmpty, removeAll, retainAll |
从类 java.lang.Object 继承的方法 |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
从接口 java.util.concurrent.BlockingQueue 继承的方法 |
---|
add |
从接口 java.util.Queue 继承的方法 |
---|
element, remove |
从接口 java.util.Collection 继承的方法 |
---|
addAll, contains, containsAll, equals, hashCode, isEmpty, removeAll, retainAll |
构造方法详细信息 |
---|
LinkedBlockingQueue
public LinkedBlockingQueue()
- Creates a LinkedBlockingQueue with a capacity of Integer.MAX_VALUE.
LinkedBlockingQueue
public LinkedBlockingQueue(int capacity)
- Creates a LinkedBlockingQueue with the given (fixed) capacity.
- 参数:
capacity
- the capacity of this queue.- 抛出:
IllegalArgumentException
- if capacity is not greater than zero.
LinkedBlockingQueue
public LinkedBlockingQueue(Collection<? extends E> c)
- Creates a LinkedBlockingQueue with a capacity of Integer.MAX_VALUE, initially containing the elements of the given collection, added in traversal order of the collection's iterator.
- 参数:
c
- the collection of elements to initially contain- 抛出:
NullPointerException
- if c or any element within it is null
方法详细信息 |
---|
size
public int size()
- Returns the number of elements in this queue.
-
- 指定者:
- 接口
Collection<E>
中的size
- 指定者:
- 类
AbstractCollection<E>
中的size
-
- 返回:
- the number of elements in this queue.
remainingCapacity
public int remainingCapacity()
- Returns the number of elements that this queue can ideally (in the absence of memory or resource constraints) accept without blocking. This is always equal to the initial capacity of this queue less the current size of this queue.
Note that you cannot always tell if an attempt to add an element will succeed by inspecting remainingCapacity because it may be the case that a waiting consumer is ready to take an element out of an otherwise full queue.
-
- 指定者:
- 接口
BlockingQueue<E>
中的remainingCapacity
-
- 返回:
- the remaining capacity
put
public void put(E o)
throws InterruptedException
- Adds the specified element to the tail of this queue, waiting if necessary for space to become available.
-
- 指定者:
- 接口
BlockingQueue<E>
中的put
-
- 参数:
o
- the element to add- 抛出:
InterruptedException
- if interrupted while waiting.NullPointerException
- if the specified element is null.
offer
public boolean offer(E o,
long timeout,
TimeUnit unit)
throws InterruptedException
- Inserts the specified element at the tail of this queue, waiting if necessary up to the specified wait time for space to become available.
-
- 指定者:
- 接口
BlockingQueue<E>
中的offer
-
- 参数:
o
- the element to addtimeout
- how long to wait before giving up, in units of unitunit
- a TimeUnit determining how to interpret the timeout parameter- 返回:
- true if successful, or false if the specified waiting time elapses before space is available.
- 抛出:
InterruptedException
- if interrupted while waiting.NullPointerException
- if the specified element is null.
offer
public boolean offer(E o)
- Inserts the specified element at the tail of this queue if possible, returning immediately if this queue is full.
-
- 指定者:
- 接口
BlockingQueue<E>
中的offer
- 指定者:
- 接口
Queue<E>
中的offer
-
- 参数:
o
- the element to add.- 返回:
- true if it was possible to add the element to this queue, else false
- 抛出:
NullPointerException
- if the specified element is null
take
public E take()
throws InterruptedException
- 从接口
BlockingQueue
复制的描述 - Retrieves and removes the head of this queue, waiting if no elements are present on this queue.
-
- 指定者:
- 接口
BlockingQueue<E>
中的take
-
- 返回:
- the head of this queue
- 抛出:
InterruptedException
- if interrupted while waiting.
poll
public E poll(long timeout,
TimeUnit unit)
throws InterruptedException
- 从接口
BlockingQueue
复制的描述 - Retrieves and removes the head of this queue, waiting if necessary up to the specified wait time if no elements are present on this queue.
-
- 指定者:
- 接口
BlockingQueue<E>
中的poll
-
- 参数:
timeout
- how long to wait before giving up, in units of unitunit
- a TimeUnit determining how to interpret the timeout parameter- 返回:
- the head of this queue, or null if the specified waiting time elapses before an element is present.
- 抛出:
InterruptedException
- if interrupted while waiting.
poll
public E poll()
- 从接口
Queue
复制的描述 - Gets and removes the element at the head of the queue, or returns
null
if there is no element in the queue. -
- 指定者:
- 接口
Queue<E>
中的poll
-
- 返回:
- the element at the head of the queue or
null
if there is no element in the queue.
peek
public E peek()
- 从接口
Queue
复制的描述 - Gets but does not remove the element at the head of the queue.
-
- 指定者:
- 接口
Queue<E>
中的peek
-
- 返回:
- the element at the head of the queue or
null
if there is no element in the queue.
remove
public boolean remove(Object o)
- 从类
AbstractCollection
复制的描述 - Removes one instance of the specified object from this
Collection
if one is contained (optional). This implementation iterates over thisCollection
and tests for each elemente
returned by the iterator, whethere
is equal to the given object. Ifobject != null
then this test is performed usingobject.equals(e)
, otherwise usingobject == null
. If an element equal to the given object is found, then theremove
method is called on the iterator andtrue
is returned,false
otherwise. If the iterator does not support removing elements, anUnsupportedOperationException
is thrown. -
- 指定者:
- 接口
Collection<E>
中的remove
- 覆盖:
- 类
AbstractCollection<E>
中的remove
-
- 参数:
o
- the object to remove.- 返回:
true
if thisCollection
is modified,false
otherwise.
toArray
public Object[] toArray()
- 从接口
Collection
复制的描述 - Returns a new array containing all elements contained in this
Collection
. If the implementation has ordered elements it will return the element array in the same order as an iterator would return them. The array returned does not reflect any changes of theCollection
. A new array is created even if the underlying data structure is already an array. -
- 指定者:
- 接口
Collection<E>
中的toArray
- 覆盖:
- 类
AbstractCollection<E>
中的toArray
-
- 返回:
- an array of the elements from this
Collection
.
toArray
public <T> T[] toArray(T[] a)
- 从接口
Collection
复制的描述 - Returns an array containing all elements contained in this
Collection
. If the specified array is large enough to hold the elements, the specified array is used, otherwise an array of the same type is created. If the specified array is used and is larger than thisCollection
, the array element following theCollection
elements is set to null. If the implementation has ordered elements it will return the element array in the same order as an iterator would return them.toArray(new Object[0])
behaves exactly the same way astoArray()
does. -
- 指定者:
- 接口
Collection<E>
中的toArray
- 覆盖:
- 类
AbstractCollection<E>
中的toArray
-
- 参数:
a
- the array.- 返回:
- an array of the elements from this
Collection
.
toString
public String toString()
- 从类
AbstractCollection
复制的描述 - Returns the string representation of this
Collection
. The presentation has a specific format. It is enclosed by square brackets ("[]"). Elements are separated by ', ' (comma and space). -
- 覆盖:
- 类
AbstractCollection<E>
中的toString
-
- 返回:
- the string representation of this
Collection
.
clear
public void clear()
- 从类
AbstractQueue
复制的描述 - Removes all elements of the queue, leaving it empty.
-
- 指定者:
- 接口
Collection<E>
中的clear
- 覆盖:
- 类
AbstractQueue<E>
中的clear
-
- 另请参见:
- AbstractCollection.iterator(), AbstractCollection.isEmpty(), AbstractCollection.size()
drainTo
public int drainTo(Collection<? super E> c)
- 从接口
BlockingQueue
复制的描述 - Removes all available elements from this queue and adds them into the given collection. This operation may be more efficient than repeatedly polling this queue. A failure encountered while attempting to add elements to collection c may result in elements being in neither, either or both collections when the associated exception is thrown. Attempts to drain a queue to itself result in IllegalArgumentException. Further, the behavior of this operation is undefined if the specified collection is modified while the operation is in progress.
-
- 指定者:
- 接口
BlockingQueue<E>
中的drainTo
-
- 参数:
c
- the collection to transfer elements into- 返回:
- the number of elements transferred.
drainTo
public int drainTo(Collection<? super E> c,
int maxElements)
- 从接口
BlockingQueue
复制的描述 - Removes at most the given number of available elements from this queue and adds them into the given collection. A failure encountered while attempting to add elements to collection c may result in elements being in neither, either or both collections when the associated exception is thrown. Attempts to drain a queue to itself result inIllegalArgumentException. Further, the behavior of this operation is undefined if the specified collection is modified while the operation is in progress.
-
- 指定者:
- 接口
BlockingQueue<E>
中的drainTo
-
- 参数:
c
- the collection to transfer elements intomaxElements
- the maximum number of elements to transfer- 返回:
- the number of elements transferred.
iterator
public Iterator<E> iterator()
- Returns an iterator over the elements in this queue in proper sequence.The returned Iterator is a "weakly consistent" iterator thatwill never throw ConcurrentModificationException,and guarantees to traverse elements as they existed uponconstruction of the iterator, and may (but is not guaranteed to)reflect any modifications subsequent to construction.
-
- 指定者:
- 接口
Iterable<E>
中的iterator
- 指定者:
- 接口
Collection<E>
中的iterator
- 指定者:
- 类
AbstractCollection<E>
中的iterator
-
- 返回:
- an iterator over the elements in this queue in proper sequence.
上一篇:FutureTaskV
LinkedBlockingQueueE(示例,出错代码)的更多相关文章
- Android视图SurfaceView的实现原理分析(示例,出错代码)
在Android系统中,有一种特殊的视图,称为SurfaceView,它拥有独立的绘图表面,即它不与其宿主窗口共享同一个绘图表面.由于拥有独立的绘图表面,因此SurfaceView的UI就可以在一个独 ...
- 高级设置电脑系统windows7防火墙出错代码0×6D9原因与解决技巧
高级设置windows防火墙能够更好的保护电脑系统安全,在电脑系统windows7设置过程中难免会遇到某些问题,有用户在安装MRGT后想要打开SNMP的161端口,但在打开高级安全windows防火墙 ...
- [示例] 用代码设置 ListView 颜色 (只适用 Win 平台,无需修改官方源码)
如果可以使用代码随意设置 ListView 的颜色,而不用加载额外的 Style 及修改官方的源码,那该有多好?! 其实 Style 提供了很强了扩充性及可塑性,可以很容易的去操作它. 下面以 Lis ...
- 入坑Intel OpenVINO:记录一个示例出错的原因和解决方法
今天试用OpenVINO的例子,在过程中发现了一些其他人没有经历的坑特别记录一下. 出错时候:执行Intel OpenVINO示例的是时候,出错的提示代码: 用于 .NET Framework 的 M ...
- jQueryMobile示例页面代码
这是一个jQueryMobile示例页面 示例效果:http://hovertree.com/texiao/jquerymobile/ 可以在手机或者触屏浏览器查看效果. 以下是HTML代码: < ...
- Delphi通过Map文件查找内存地址出错代码所在行
一 什么是MAP文件 什么是 MAP 文件?简单地讲, MAP 文件是程序的全局符号.源文件和代码行号信息的唯一的文本表示方法,它可以在任何地方.任何时候使用,不需要有额外的程序进行支持.而且,这是唯 ...
- 问题-[Delphi]通过Map文件查找内存地址出错代码所在行
一 什么是MAP文件 什么是 MAP 文件?简单地讲, MAP 文件是程序的全局符号.源文件和代码行号信息的唯一的文本表示方法,它可以在任何地方.任何时候使用,不需要有额外的程序进行支持 ...
- asp.net中使用Global.asax文件中添加应用出错代码,写入系统日志文件或数据库
void Application_Error(object sender, EventArgs e) { // 在出现未处理的错误时运行的代码 Exception objErr = Server.Ge ...
- SpriteBuilder改变布局后App运行出错代码排查
原来整个关卡场景放在GameScene.ccb中,后来觉得移到专门的Level.ccb比较好. 移动过后编译运行,只要移动Player的胳膊发射子弹时,Xcode报错: g due to Chipmu ...
随机推荐
- BufferedReader与Scanner的区别
在Java中,我们都知道Java的标准输入串是System.in.但是我们却很少在Java中看到谁使用它,这是因为我们平时输入的都是一个字符串或者是一个数字等等.而System.in提供的read方法 ...
- PL/SQL Developer安装详解(32位客户端免安装版)
PL/SQL Developer是一个集成开发环境,专门开发面向Oracle数据库的应用.PL/SQL也是一种程序语言,叫做过程化SQL语言(Procedural Language/SQL).PL/S ...
- C# 把背景为白色的图片变成透明图片
Image Imageimage; Imageimage = System.Drawing.Image.FromFile(@"C:\A.JPG"); Bitmap bitmap = ...
- Android 常用操作
0.android studios使用介绍 使用介绍 android studio 常用小技巧 网址 1.怎么样添加第三方库 方法一: 第一步:将第三方库以module的形式导入 第二步:选中要导入第 ...
- vs加js引用
今天又有一个同事问我“在VS中如何让一个JS文件智能提示另一个JS文件中的成员”,他说Google了一下,并没有找到答案,然后我把这个小技巧贴出来,希望能被Google到. 有时候会有这种情况:当我的 ...
- js中的this,call及apply
在前端网看了这么一篇文章,觉得讲得还不错,不深入但易懂,所以我这里把这个经典的问题也记下来. 1:声明式函数与定义函数表达式 console.log(f1);//f1() console.log(f2 ...
- 设置 phoneGap/Cordova 3.4 应用程序启动动画闪屏 SplashScreen
当Cordova 程序打包并安装到手机中后,我们会发现启动程序时,会有数秒的黑屏现象,常见的解决方法则是设置闪屏后面. 这里以 Android 程序为例,介绍Cordova设置启动画面的方法. 1. ...
- 使用java mail 发送邮件
1.关联jar包: activation.jar mail.jar 2.调用 @Test public void test1() { List<String> imageUrlLi ...
- 基于php开发的RESTful ApiDoc文档
apiDoc基于rest的web API文档生成器,可以根据代码注释生成web api文档,自动生成静态的html网页文档,不仅支持项目版本号,还支持API版本号. 使用apiDoc不需要自己麻烦的调 ...
- 面试题HTML +CSS
HTML+CSS部分1.行内元素和块级元素?img算什么?行内元素怎么转化为块级元素?行内元素:和有他元素都在一行上,高度.行高及外边距和内边距都不可改变,文字图片的宽度不可改变,只能容纳文本或者其他 ...