E
-元素举行此集合中的类型
public interface TransferQueue<E> extends BlockingQueue<E>
BlockingQueue
,生产者可以等待消费者接收元件。一个
TransferQueue
可能有用的消息传递应用程序以生产者有时(使用方法
transfer(E)
)等待消费者调用
take
或
poll
收据的元素,而在其他时间入队元素(通过方法
put
)无需等待收据。
Non-blocking和
tryTransfer
time-out版本也可。一个
TransferQueue
也可以进行查询,通过
hasWaitingConsumer()
,是否有任何线程等待的项目,这是一个逆向的比喻为一个
peek
操作。
像其他的阻塞队列,一个TransferQueue
可能能力有限。如果是这样的话,一个尝试传输操作可能会开始块等待可用的空间,和/或随后块等待由一个消费者的接收。值得注意的是,队列中的零能力,如SynchronousQueue
,put
和transfer
有效的代名词。
该接口的 Java Collections Framework成员。
Modifier and Type | Method and Description |
---|---|
int |
getWaitingConsumerCount()
回报消费者的数量估计等待通过
BlockingQueue.take() 接收元件或定时
poll 。
|
boolean |
hasWaitingConsumer()
|
void |
transfer(E e)
将元素转移到一个消费者,如果有必要的话,等待。
|
boolean |
tryTransfer(E e)
如果可能的话,立即将该元素转移到等待的消费者。
|
boolean |
tryTransfer(E e, long timeout, TimeUnit unit)
将元素对消费者是否可以这样做,在超时之前逝去。
|
add, contains, drainTo, drainTo, offer, offer, poll, put, remainingCapacity, remove, take
addAll, clear, containsAll, equals, hashCode, isEmpty, iterator, parallelStream, removeAll, removeIf, retainAll, size, spliterator, stream, toArray, toArray
boolean tryTransfer(E e)
更确切地说,将指定元素立即如果存在一个消费者已经等待接收它(在BlockingQueue.take()
或定时poll
),否则返回false
没有入队的元素。
e
-元素转移
true
如果元素被转移,其他
false
ClassCastException
-如果指定元素类型阻止其加入队列
NullPointerException
-如果指定元素为null
IllegalArgumentException
-如果指定元素的一些特性阻止其加入队列
void transfer(E e) throws InterruptedException
更确切地说,将指定元素立即如果存在一个消费者已经等待接收它(在BlockingQueue.take()
或定时poll
),否则等到元素是由消费者接受。
e
-元素转移
InterruptedException
如果中断而等待,在这种情况下,元素不离开队列
ClassCastException
-如果指定元素类型阻止其加入队列
NullPointerException
-如果指定元素为null
IllegalArgumentException
-如果指定元素的一些特性阻止其加入队列
boolean tryTransfer(E e, long timeout, TimeUnit unit) throws InterruptedException
更确切地说,将指定元素立即如果存在一个消费者已经等待接收它(在BlockingQueue.take()
或定时poll
),否则等到元素是由消费者的接受,还false
如果指定的等待时间过去之前的元素可以被转移。
e
-元素转移
timeout
-多久才放弃等待,在单位
unit
unit
-
TimeUnit
确定如何解释
timeout
参数
true
如果成功,或
false
如果指定的等待时间结束之前完成,在这种情况下,元素不离开队列
InterruptedException
如果中断而等待,在这种情况下,元素不离开队列
ClassCastException
-如果指定元素类型阻止其加入队列
NullPointerException
-如果指定元素为null
IllegalArgumentException
-如果指定元素的一些特性阻止其加入队列
boolean hasWaitingConsumer()
true
如果至少有一个等待消费者
int getWaitingConsumerCount()
BlockingQueue.take()
接收元件或定时
poll
。返回值是一个近似的一个短暂的状态,这可能是不准确的,如果消费者已经完成或放弃等待。该值可能是有用的监测和启发式,但不同步控制。此方法的实现可能会比
hasWaitingConsumer()
明显慢。
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.