E - 在这个集合中保存的元素的类型
public interface TransferQueue<E> extends BlockingQueue<E>
BlockingQueue其中生产者可以等待消费者接收元素。
A TransferQueue可用于例如消息传递应用程序,其中生产者有时(使用方法transfer(E) )等待消费者调用take或poll ,而在其他时间,等待元素(通过方法put )而不等待接收。
Non-blocking和time-out版本的tryTransfer也可用。
甲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, takeaddAll, clear, containsAll, equals, hashCode, isEmpty, iterator, parallelStream, removeAll, removeIf, retainAll, size, spliterator, stream, toArray, toArrayboolean tryTransfer(E e)
更确切地说,如果存在消费者已经在等待接收它(在BlockingQueue.take()或定时的poll ),则立即false指定的元素,否则返回false而不必插入元素。
e - 要传输的元素
true如果元素被转移,否则
false
ClassCastException - 如果指定元素的类阻止将其添加到此队列中
NullPointerException - 如果指定的元素为空
IllegalArgumentException - 如果指定元素的某些属性阻止将其添加到此队列中
void transfer(E e) throws InterruptedException
更确切地说,如果存在已经等待接收消费者的消费者( BlockingQueue.take()或定时器poll ),则立即转移指定元素,否则等待消费者收到该元素。
e - 要传输的元素
InterruptedException - 如果在等待时中断,在这种情况下元素不会被排入队列
ClassCastException - 如果指定元素的类阻止将其添加到此队列中
NullPointerException - 如果指定的元素为空
IllegalArgumentException - 如果指定元素的某些属性阻止将其添加到此队列中
boolean tryTransfer(E e, long timeout, TimeUnit unit) throws InterruptedException
更准确地说,指定的元素立即转移,如果存在一个消费者已经等待接收(在BlockingQueue.take()或定时poll ),否则等待,直到元素被消费者接受,返回false如果指定的等待时间因素逝去前可转入。
e - 要传输的元素
timeout - 放弃等待多久,以
unit为单位
unit - a
TimeUnit确定如何解释
timeout参数
true如果成功,或
false如果在完成之前经过了指定的等待时间,在这种情况下,元素不会排入队列
InterruptedException - 如果在等待时中断,在这种情况下元素不会被排入队列
ClassCastException - 如果指定元素的类阻止将其添加到此队列中
NullPointerException - 如果指定的元素为空
IllegalArgumentException - 如果指定元素的某些属性阻止其添加到此队列中
boolean hasWaitingConsumer()
true如果存在至少一个消费者等待经由以接收元件BlockingQueue.take()或定时poll 。
返回值代表一时的状态。
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.