E
-元素举行此集合中的类型
public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E>
Deque
,等待空间变得可用时在deque容器存储元件。
BlockingDeque
方法有四种形式,不同的处理操作,不能立即满足的方式,但可以满足在未来的某一时刻:一个抛出一个异常,第二返回一个特殊值(或null
或false
,取决于操作),第三块的当前线程直到操作成功,只为一个给定的时间限制在放弃之前的第四块。这些方法汇总在下表中:
First Element (Head) | ||||
Throws exception | Special value | Blocks | Times out | |
Insert | addFirst(e) |
offerFirst(e) |
putFirst(e) |
offerFirst(e, time, unit) |
Remove | removeFirst() |
pollFirst() |
takeFirst() |
pollFirst(time, unit) |
Examine | getFirst() |
peekFirst() |
not applicable | not applicable |
Last Element (Tail) | ||||
Throws exception | Special value | Blocks | Times out | |
Insert | addLast(e) |
offerLast(e) |
putLast(e) |
offerLast(e, time, unit) |
Remove | removeLast() |
pollLast() |
takeLast() |
pollLast(time, unit) |
Examine | getLast() |
peekLast() |
not applicable | not applicable |
像任何BlockingQueue
,一BlockingDeque
是线程安全的,不允许null元素,可能(或不可能)有能力约束。
一个BlockingDeque
实施可直接使用FIFO作为BlockingQueue
。方法继承了BlockingQueue
接口相当于BlockingDeque
方法如下表所示:
BlockingQueue Method |
Equivalent BlockingDeque Method |
Insert | |
add(e) |
addLast(e) |
offer(e) |
offerLast(e) |
put(e) |
putLast(e) |
offer(e, time, unit) |
offerLast(e, time, unit) |
Remove | |
remove() |
removeFirst() |
poll() |
pollFirst() |
take() |
takeFirst() |
poll(time, unit) |
pollFirst(time, unit) |
Examine | |
element() |
getFirst() |
peek() |
peekFirst() |
内存一致性效果:与其他并发集合,在将对象放入一个BlockingDeque
happen-before行动从另一个线程的BlockingDeque
元素的访问和去除之前的线程的行为。
该接口的 Java Collections Framework成员。
Modifier and Type | Method and Description |
---|---|
boolean |
add(E e)
插入指定元素为代表的deque队列(换句话说,在这个队列尾)如果可能立即这样做不违反容量限制,还
true 成功后抛出
IllegalStateException 如果没有空间是可用的。
|
void |
addFirst(E e)
插入指定元素在队列前面是否有可能立即这样做不违反容量限制,抛出一个
IllegalStateException 如果没有空间是可用的。
|
void |
addLast(E e)
插入指定元素在这个队列的最后如果可能立即这样做不违反容量限制,抛出一个
IllegalStateException 如果没有空间是可用的。
|
boolean |
contains(Object o)
如果这两
true 返回包含指定的元素。
|
E |
element()
检索,但不删除,这代表的deque队列的头部(换句话说,这个容器的第一个元素)。
|
Iterator<E> |
iterator()
返回以正确的顺序在deque容器元素的迭代器。
|
boolean |
offer(E e)
插入指定元素为代表的deque队列(换句话说,在这个队列尾)如果可能立即这样做不违反容量限制,还
true 在成功和
false 如果没有空间是可用的。
|
boolean |
offer(E e, long timeout, TimeUnit unit)
插入指定元素为代表的deque队列(换句话说,在这个队列的尾部),等待到指定的等待时间,如果空间成为必要。
|
boolean |
offerFirst(E e)
插入指定元素在队列前面是否有可能立即这样做不违反容量限制,还
true 在成功和
false 如果没有空间是可用的。
|
boolean |
offerFirst(E e, long timeout, TimeUnit unit)
在这个队列的前面插入指定元素,等待到指定的等待时间,如果空间成为必要。
|
boolean |
offerLast(E e)
插入指定元素在这个队列的最后如果可能立即这样做不违反容量限制,还
true 在成功和
false 如果没有空间是可用的。
|
boolean |
offerLast(E e, long timeout, TimeUnit unit)
在这个队列的末尾插入指定元素,等待到指定的等待时间,如果空间成为必要。
|
E |
peek()
检索,但不删除,这代表的deque队列的头部(换句话说,这个容器的第一个元素),或返回
null 如果队列是空的。
|
E |
poll()
检索并移除该deque表示队列的头部(换句话说,这个容器的第一个元素),或返回
null 如果队列是空的。
|
E |
poll(long timeout, TimeUnit unit)
检索并移除该deque表示队列的头部(换句话说,这个容器的第一个元素),等待到指定的等待时间,如果一个元素成为必要。
|
E |
pollFirst(long timeout, TimeUnit unit)
检索并移除此队列的第一个元素,等待到指定的等待时间,如果一个元素成为必要。
|
E |
pollLast(long timeout, TimeUnit unit)
检索并移除此队列的最后一个元素,等待到指定的等待时间,如果一个元素成为必要。
|
void |
push(E e)
将一个元素到该deque表示堆栈(换句话说,在这个队列的头)如果可能立即这样做不违反容量限制,抛出一个
IllegalStateException 如果没有空间是可用的。
|
void |
put(E e)
插入指定元素为代表的deque队列(换句话说,在这个队列的尾部),如果空间成为提供必要的等待。
|
void |
putFirst(E e)
在这个队列的前面插入指定元素,如果空间成为提供必要的等待。
|
void |
putLast(E e)
在这个队列的末尾插入指定元素,如果空间成为提供必要的等待。
|
E |
remove()
检索并移除该deque表示队列的头部(换句话说,这个容器的第一个元素)。
|
boolean |
remove(Object o)
删除第一个出现的指定元素从这个队列。
|
boolean |
removeFirstOccurrence(Object o)
删除第一个出现的指定元素从这个队列。
|
boolean |
removeLastOccurrence(Object o)
移除指定元素的最后出现从这个队列。
|
int |
size()
返回该容器元素的数量。
|
E |
take()
检索并移除该deque表示队列的头部(换句话说,这个容器的第一个元素),必要时可用等待直到元。
|
E |
takeFirst()
检索并移除此队列的第一个元素,如果有必要,直到一个元素可用等。
|
E |
takeLast()
检索并移除此队列的最后一个元素,如果有必要,直到一个元素可用等。
|
drainTo, drainTo, remainingCapacity
descendingIterator, getFirst, getLast, peekFirst, peekLast, pollFirst, pollLast, pop, removeFirst, removeLast
addAll, clear, containsAll, equals, hashCode, isEmpty, parallelStream, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArray
void addFirst(E e)
IllegalStateException
如果没有空间是可用的。使用容量限制容器时,它是通常最好使用
offerFirst
。
addFirst
接口
Deque<E>
e
-元素添加
IllegalStateException
-如果元素不能被添加在这个时候由于产能限制
ClassCastException
-如果指定元素类型阻止其加入队列
NullPointerException
-如果指定元素为null
IllegalArgumentException
-如果指定元素的一些特性阻止其加入队列
void addLast(E e)
IllegalStateException
如果没有空间是可用的。使用容量限制容器时,它是通常最好使用
offerLast
。
addLast
接口
Deque<E>
e
-元素添加
IllegalStateException
-如果元素不能被添加在这个时候由于产能限制
ClassCastException
-如果指定元素类型阻止其加入队列
NullPointerException
-如果指定元素为null
IllegalArgumentException
-如果指定元素的一些特性阻止其加入队列
boolean offerFirst(E e)
true
在成功和
false
如果没有空间是可用的。使用容量限制队列时,这种方法是最好的
addFirst
方法,可不能只通过抛出异常,插入一个元素。
offerFirst
接口
Deque<E>
e
-元素添加
true
如果元素被添加到这个容器,其他
false
ClassCastException
-如果指定元素类型阻止其加入队列
NullPointerException
-如果指定元素为null
IllegalArgumentException
-如果指定元素的一些特性阻止其加入队列
boolean offerLast(E e)
true
在成功和
false
如果没有空间是可用的。使用容量限制队列时,这种方法是最好的
addLast
方法,可不能只通过抛出异常,插入一个元素。
offerLast
接口
Deque<E>
e
-元素添加
true
如果元素被添加到这个容器,其他
false
ClassCastException
-如果指定元素类型阻止其加入队列
NullPointerException
-如果指定元素为null
IllegalArgumentException
-如果指定元素的一些特性阻止其加入队列
void putFirst(E e) throws InterruptedException
e
-元素添加
InterruptedException
如果中断等待
ClassCastException
-如果指定元素类型阻止其加入队列
NullPointerException
-如果指定元素为null
IllegalArgumentException
-如果指定元素的一些特性阻止其加入队列
void putLast(E e) throws InterruptedException
e
-元素添加
InterruptedException
如果中断等待
ClassCastException
-如果指定元素类型阻止其加入队列
NullPointerException
-如果指定元素为null
IllegalArgumentException
-如果指定元素的一些特性阻止其加入队列
boolean offerFirst(E e, long timeout, TimeUnit unit) throws InterruptedException
e
-元素添加
timeout
-多久才放弃等待,在单位
unit
unit
-
TimeUnit
确定如何解释
timeout
参数
true
如果成功,或
false
如果指定的等待时间过去之前可用空间
InterruptedException
如果中断等待
ClassCastException
-如果指定元素类型阻止其加入队列
NullPointerException
-如果指定元素为null
IllegalArgumentException
-如果指定元素的一些特性阻止其加入队列
boolean offerLast(E e, long timeout, TimeUnit unit) throws InterruptedException
e
-元素添加
timeout
-多久才放弃等待,在单位
unit
unit
-
TimeUnit
确定如何解释
timeout
参数
true
如果成功,或
false
如果指定的等待时间过去之前可用空间
InterruptedException
如果中断等待
ClassCastException
-如果指定元素类型阻止其加入队列
NullPointerException
-如果指定元素为null
IllegalArgumentException
-如果指定元素的一些特性阻止其加入队列
E takeFirst() throws InterruptedException
InterruptedException
如果中断等待
E takeLast() throws InterruptedException
InterruptedException
如果中断等待
E pollFirst(long timeout, TimeUnit unit) throws InterruptedException
timeout
-多久才放弃等待,在单位
unit
unit
-
TimeUnit
确定如何解释
timeout
参数
null
如果指定的等待时间过去之前一个元素是可用的
InterruptedException
如果中断等待
E pollLast(long timeout, TimeUnit unit) throws InterruptedException
timeout
-多久才放弃等待,在单位
unit
unit
-
TimeUnit
确定如何解释
timeout
参数
null
如果指定的等待时间过去之前一个元素是可用的
InterruptedException
如果中断等待
boolean removeFirstOccurrence(Object o)
o.equals(e)
第一单元
e
(如果这样一个元素存在)。如果这两
true
返回包含指定元素(或等价地,如果调用的结果这的确改变了)。
removeFirstOccurrence
接口
Deque<E>
o
元要从队列移除,如果存在
true
如果元素是作为一个结果,这叫删除
ClassCastException
如果指定元素的类是不兼容的(这两
optional)
NullPointerException
-如果指定元素为null(
optional)
boolean removeLastOccurrence(Object o)
o.equals(e)
移除最后一个元素
e
(如果这样一个元素存在)。如果这两
true
返回包含指定元素(或等价地,如果调用的结果这的确改变了)。
removeLastOccurrence
接口
Deque<E>
o
元要从队列移除,如果存在
true
如果元素是作为一个结果,这叫删除
ClassCastException
如果指定元素的类是不兼容的(这两
optional)
NullPointerException
-如果指定元素为null(
optional)
boolean add(E e)
true
成功后抛出
IllegalStateException
如果没有空间是可用的。使用容量限制容器时,它是通常最好使用
offer
。
这种方法相当于addLast
。
add
接口
BlockingQueue<E>
add
接口
Collection<E>
add
接口
Deque<E>
add
接口
Queue<E>
e
-元素添加
true
(由
Collection.add(E)
指定)
IllegalStateException
-如果元素不能被添加在这个时候由于产能限制
ClassCastException
-如果指定元素类型阻止其加入队列
NullPointerException
-如果指定元素为null
IllegalArgumentException
-如果指定元素的一些特性阻止其加入队列
boolean offer(E e)
true
在成功和
false
如果没有空间是可用的。使用容量限制队列时,这种方法是最好的
add(E)
方法,可不能只通过抛出异常,插入一个元素。
这种方法相当于offerLast
。
offer
接口
BlockingQueue<E>
offer
接口
Deque<E>
offer
接口
Queue<E>
e
-元素添加
true
如果元素被添加到这个队列,否则
false
ClassCastException
-如果指定元素类型阻止其加入队列
NullPointerException
-如果指定元素为null
IllegalArgumentException
-如果指定元素的一些特性阻止其加入队列
void put(E e) throws InterruptedException
这种方法相当于putLast
。
put
接口
BlockingQueue<E>
e
-元素添加
InterruptedException
如果中断等待
ClassCastException
-如果指定元素类型阻止其加入队列
NullPointerException
-如果指定元素为null
IllegalArgumentException
-如果指定元素的一些特性阻止其加入队列
boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException
这种方法相当于offerLast
。
offer
接口
BlockingQueue<E>
e
-元素添加
timeout
-多久才放弃等待,在单位
unit
unit
-
TimeUnit
确定如何解释
timeout
参数
true
如果元素被添加到这个容器,其他
false
InterruptedException
如果中断等待
ClassCastException
-如果指定元素类型阻止其加入队列
NullPointerException
-如果指定元素为null
IllegalArgumentException
-如果指定元素的一些特性阻止其加入队列
E remove()
poll
仅在于它抛出一个异常,如果这个容器是空的。
这种方法相当于removeFirst
。
E poll()
null
如果队列是空的。
这种方法相当于Deque.pollFirst()
。
E take() throws InterruptedException
这种方法相当于takeFirst
。
take
接口
BlockingQueue<E>
InterruptedException
如果中断等待
E poll(long timeout, TimeUnit unit) throws InterruptedException
这种方法相当于pollFirst
。
poll
接口
BlockingQueue<E>
timeout
-多久才放弃等待,在单位
unit
unit
-
TimeUnit
确定如何解释
timeout
参数
null
如果指定的等待时间过去之前一个元素是可用的
InterruptedException
如果中断等待
E element()
boolean remove(Object o)
o.equals(e)
第一单元
e
(如果这样一个元素存在)。如果这两
true
返回包含指定元素(或等价地,如果调用的结果这的确改变了)。
这种方法相当于removeFirstOccurrence
。
remove
接口
BlockingQueue<E>
remove
接口
Collection<E>
remove
接口
Deque<E>
o
元要从队列移除,如果存在
true
如果调用的结果这的确改变了
ClassCastException
如果指定元素的类是不兼容的(这两
optional)
NullPointerException
-如果指定元素为null(
optional)
boolean contains(Object o)
true
返回包含指定的元素。更正式地说,返回
true
当且仅当这个容器包含至少一个元素
e
这样
o.equals(e)
。
contains
接口
BlockingQueue<E>
contains
接口
Collection<E>
contains
接口
Deque<E>
o
对象进行检查在deque容器
true
包含指定的元素
ClassCastException
如果指定元素的类是不兼容的(这两
optional)
NullPointerException
-如果指定元素为null(
optional)
int size()
void push(E e)
IllegalStateException
如果没有空间是可用的。
这种方法相当于addFirst
。
push
接口
Deque<E>
e
-元推
IllegalStateException
-如果元素不能被添加在这个时候由于产能限制
ClassCastException
-如果指定元素类型阻止其加入队列
NullPointerException
-如果指定元素为null
IllegalArgumentException
-如果指定元素的一些特性阻止其加入队列
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.