E
-元素举行此集合中的类型
public class LinkedTransferQueue<E> extends AbstractQueue<E> implements TransferQueue<E>, Serializable
TransferQueue
。这个队列的命令元素的FIFO(先进先出)对于任何给定的生产。队列的头是已在队列中的元素,是某一生产商的最长时间。队列的尾部是已在队列中的元素,一些生产者的最短时间。
要小心的是,不像大多数集合的方法,size
不是常量时间的操作。由于这些队列的异步性质,确定当前元素的数量需要一个元素的遍历,如果这个集合在遍历过程中被修改,那么可能会报告不准确的结果。此外,大容量操作addAll
,removeAll
,retainAll
,containsAll
,equals
,和toArray
不保证是自动执行。例如,一个addAll
并发运行的操作一个迭代器可能会认为只有一些加入的元素。
这个类和它的迭代器实现所有的可选方法的Collection
和Iterator
接口。
内存一致性效果:与其他并发集合,在将对象放入一个LinkedTransferQueue
happen-before行动从另一个线程的LinkedTransferQueue
元素的访问和去除之前的线程的行为。
这个班的一员 Java Collections Framework。
Constructor and Description |
---|
LinkedTransferQueue()
创建一个空的
LinkedTransferQueue 。
|
LinkedTransferQueue(Collection<? extends E> c)
创建一个
LinkedTransferQueue 最初包含元素的集合,加入集合的迭代器遍历顺序。
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(E e)
在这个队列的尾部插入指定的元素。
|
boolean |
contains(Object o)
返回
true 如果此队列包含指定的元素。
|
int |
drainTo(Collection<? super E> c)
从这个队列中删除所有可用的元素,并将它们添加到给定的集合中。
|
int |
drainTo(Collection<? super E> c, int maxElements)
从这个队列中移除给定数量的可用元素,并将它们添加到给定的集合中。
|
int |
getWaitingConsumerCount()
回报消费者的数量估计等待通过
BlockingQueue.take() 接收元件或定时
poll 。
|
boolean |
hasWaitingConsumer()
|
boolean |
isEmpty()
返回
true 如果队列不包含元素。
|
Iterator<E> |
iterator()
在这个队列中的元素上返回一个正确的顺序。
|
boolean |
offer(E e)
在这个队列的尾部插入指定的元素。
|
boolean |
offer(E e, long timeout, TimeUnit unit)
在这个队列的尾部插入指定的元素。
|
E |
peek()
检索,但不删除,这个队列头,或返回
null 如果队列为空。
|
E |
poll()
检索并移除此队列的头,或返回
null 如果队列为空。
|
E |
poll(long timeout, TimeUnit unit)
检索和删除此队列的头,等待指定的等待时间,如果需要的元素成为可用。
|
void |
put(E e)
在这个队列的尾部插入指定的元素。
|
int |
remainingCapacity()
总是返回
Integer.MAX_VALUE 因为
LinkedTransferQueue 没有容量限制。
|
boolean |
remove(Object o)
从该队列中移除指定元素的一个实例,如果它是存在的。
|
int |
size()
返回此队列中的元素的数目。
|
Spliterator<E> |
spliterator()
返回队列中的元素在这一
Spliterator 。
|
E |
take()
检索并移除此队列的头,在必要时等待,直到一个元素可用。
|
void |
transfer(E e)
将元素转移到一个消费者,如果有必要的话,等待。
|
boolean |
tryTransfer(E e)
如果可能的话,立即将该元素转移到等待的消费者。
|
boolean |
tryTransfer(E e, long timeout, TimeUnit unit)
将元素对消费者是否可以这样做,在超时之前逝去。
|
addAll, clear, element, remove
containsAll, removeAll, retainAll, toArray, toArray, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addAll, clear, containsAll, equals, hashCode, parallelStream, removeAll, removeIf, retainAll, stream, toArray, toArray
public LinkedTransferQueue()
LinkedTransferQueue
。
public LinkedTransferQueue(Collection<? extends E> c)
LinkedTransferQueue
最初包含元素的集合,加入集合的迭代器遍历顺序。
c
-最初包含元素的集合
NullPointerException
-如果指定集合或其任何元素都是空的
public Spliterator<E> spliterator()
Spliterator
。
返回的spliterator是weakly consistent。
报告的Spliterator
Spliterator.CONCURRENT
,Spliterator.ORDERED
,和Spliterator.NONNULL
。
spliterator
接口
Iterable<E>
spliterator
接口
Collection<E>
Spliterator
trySplit
允许有限的并行实现。
Spliterator
public void put(E e)
put
接口
BlockingQueue<E>
e
-元素添加
NullPointerException
-如果指定元素为null
public boolean offer(E e, long timeout, TimeUnit unit)
false
。
offer
接口
BlockingQueue<E>
e
-元素添加
timeout
-多久才放弃等待,在单位
unit
unit
-
TimeUnit
确定如何解释
timeout
参数
true
(由
BlockingQueue.offer
指定)
NullPointerException
-如果指定元素为null
public boolean offer(E e)
false
。
offer
接口
BlockingQueue<E>
offer
接口
Queue<E>
e
-元素添加
true
(由
Queue.offer(E)
指定)
NullPointerException
-如果指定元素为null
public boolean add(E e)
IllegalStateException
或返回
false
。
add
接口
Collection<E>
add
接口
BlockingQueue<E>
add
接口
Queue<E>
add
方法重写,继承类
AbstractQueue<E>
e
-元素添加
true
(由
Collection.add(E)
指定)
NullPointerException
-如果指定元素为null
public boolean tryTransfer(E e)
tryTransfer
接口
TransferQueue<E>
e
-元素转移
true
如果元素被转移,其他
false
NullPointerException
-如果指定元素为null
public void transfer(E e) throws InterruptedException
transfer
接口
TransferQueue<E>
e
-元素转移
NullPointerException
-如果指定元素为null
InterruptedException
如果中断而等待,在这种情况下,元素不离开队列
public boolean tryTransfer(E e, long timeout, TimeUnit unit) throws InterruptedException
更确切地说,将指定元素立即如果存在一个消费者已经等待接收它(在take()
或定时poll
),否则插入指定元素在这个队列尾等元素是由消费者的接受,还false
如果指定的等待时间过去之前的元素可以被转移。
tryTransfer
接口
TransferQueue<E>
e
-元素转移
timeout
-多久才放弃等待,在单位
unit
unit
-
TimeUnit
确定如何解释
timeout
参数
true
如果成功,或
false
如果指定的等待时间结束之前完成,在这种情况下,元素不离开队列
NullPointerException
-如果指定元素为null
InterruptedException
如果中断而等待,在这种情况下,元素不离开队列
public E take() throws InterruptedException
BlockingQueue
take
接口
BlockingQueue<E>
InterruptedException
如果中断等待
public E poll(long timeout, TimeUnit unit) throws InterruptedException
BlockingQueue
poll
接口
BlockingQueue<E>
timeout
-多久才放弃等待,在单位
unit
unit
-
TimeUnit
确定如何解释
timeout
参数
null
如果指定的等待时间过去之前一个元素是可用的
InterruptedException
如果中断等待
public int drainTo(Collection<? super E> c)
BlockingQueue
c
添加元素可能会导致元素在没有遭遇过失败,或集合时相关的异常被抛出。试图排队列本身造成
IllegalArgumentException
。此外,当操作正在进行中时,此操作的行为是不确定的,如果指定的集合被修改了。
drainTo
接口
BlockingQueue<E>
c
-收集传递元素
NullPointerException
-如果指定集合为空
IllegalArgumentException
-如果指定集合的队列,该队列或一个元素的一些特性可以防止它被添加到指定的集合
public int drainTo(Collection<? super E> c, int maxElements)
BlockingQueue
c
添加元素可能会导致元素在没有遭遇过失败,或集合时相关的异常被抛出。试图排队列本身造成
IllegalArgumentException
。此外,当操作正在进行中时,此操作的行为是不确定的,如果指定的集合被修改了。
drainTo
接口
BlockingQueue<E>
c
-收集传递元素
maxElements
-元素的最大数量的转移
NullPointerException
-如果指定集合为空
IllegalArgumentException
-如果指定集合的队列,该队列或一个元素的一些特性可以防止它被添加到指定的集合
public Iterator<E> iterator()
返回的迭代器是weakly consistent。
iterator
接口
Iterable<E>
iterator
接口
Collection<E>
iterator
方法重写,继承类
AbstractCollection<E>
public boolean isEmpty()
true
如果队列不包含元素。
isEmpty
接口
Collection<E>
isEmpty
方法重写,继承类
AbstractCollection<E>
true
如果队列不包含元素
public boolean hasWaitingConsumer()
TransferQueue
hasWaitingConsumer
接口
TransferQueue<E>
true
如果至少有一个等待消费者
public int size()
Integer.MAX_VALUE
元素,返回
Integer.MAX_VALUE
。
请注意,与大多数集合不同,此方法不是一个常数时间操作。由于这些队列的异步性质,确定当前元素的当前数量需要一个O(n)遍历。
size
接口
Collection<E>
size
方法重写,继承类
AbstractCollection<E>
public int getWaitingConsumerCount()
TransferQueue
BlockingQueue.take()
接收元件或定时
poll
。返回值是一个近似的一个短暂的状态,这可能是不准确的,如果消费者已经完成或放弃等待。该值可能是有用的监测和启发式,但不同步控制。此方法的实现可能会比
TransferQueue.hasWaitingConsumer()
明显慢。
getWaitingConsumerCount
接口
TransferQueue<E>
public boolean remove(Object o)
e
这样
o.equals(e)
,如果此队列包含一个或多个这样的元素。返回
true
如果此队列包含指定元素(或等价地,如果调用的结果这个队列改变)。
remove
接口
Collection<E>
remove
接口
BlockingQueue<E>
remove
方法重写,继承类
AbstractCollection<E>
o
元素被从队列中删除,如果存在
true
如果调用的结果改变了这个队列
public boolean contains(Object o)
true
如果此队列包含指定的元素。更正式地说,返回
true
当且仅当该队列包含至少一个元素
e
这样
o.equals(e)
。
contains
接口
Collection<E>
contains
接口
BlockingQueue<E>
contains
方法重写,继承类
AbstractCollection<E>
o
对象需要检查该队列中的遏制
true
如果此队列包含指定的元素
public int remainingCapacity()
Integer.MAX_VALUE
因为
LinkedTransferQueue
没有容量限制。
remainingCapacity
接口
BlockingQueue<E>
Integer.MAX_VALUE
(由
BlockingQueue.remainingCapacity
指定)
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.