1 *java.util.concurrent.BlockingDeque* *BlockingDeque* ADequethat additionally sup
3 public interface interface BlockingDeque<E>
5 implements |java.util.concurrent.BlockingQueue|
8 |java.util.concurrent.BlockingDeque_Description|
9 |java.util.concurrent.BlockingDeque_Fields|
10 |java.util.concurrent.BlockingDeque_Constructors|
11 |java.util.concurrent.BlockingDeque_Methods|
13 ================================================================================
15 *java.util.concurrent.BlockingDeque_Methods*
16 |java.util.concurrent.BlockingDeque.add(E)|Inserts the specified element into t
17 |java.util.concurrent.BlockingDeque.addFirst(E)|Inserts the specified element a
18 |java.util.concurrent.BlockingDeque.addLast(E)|Inserts the specified element at
19 |java.util.concurrent.BlockingDeque.contains(Object)|Returns true if this deque
20 |java.util.concurrent.BlockingDeque.element()|Retrieves, but does not remove, t
21 |java.util.concurrent.BlockingDeque.iterator()|Returns an iterator over the ele
22 |java.util.concurrent.BlockingDeque.offer(E)|Inserts the specified element into
23 |java.util.concurrent.BlockingDeque.offer(E,long,TimeUnit)|Inserts the specifie
24 |java.util.concurrent.BlockingDeque.offerFirst(E)|Inserts the specified element
25 |java.util.concurrent.BlockingDeque.offerFirst(E,long,TimeUnit)|Inserts the spe
26 |java.util.concurrent.BlockingDeque.offerLast(E)|Inserts the specified element
27 |java.util.concurrent.BlockingDeque.offerLast(E,long,TimeUnit)|Inserts the spec
28 |java.util.concurrent.BlockingDeque.peek()|Retrieves, but does not remove, the
29 |java.util.concurrent.BlockingDeque.poll()|Retrieves and removes the head of th
30 |java.util.concurrent.BlockingDeque.poll(long,TimeUnit)|Retrieves and removes t
31 |java.util.concurrent.BlockingDeque.pollFirst(long,TimeUnit)|Retrieves and remo
32 |java.util.concurrent.BlockingDeque.pollLast(long,TimeUnit)|Retrieves and remov
33 |java.util.concurrent.BlockingDeque.push(E)|Pushes an element onto the stack re
34 |java.util.concurrent.BlockingDeque.put(E)|Inserts the specified element into t
35 |java.util.concurrent.BlockingDeque.putFirst(E)|Inserts the specified element a
36 |java.util.concurrent.BlockingDeque.putLast(E)|Inserts the specified element at
37 |java.util.concurrent.BlockingDeque.remove()|Retrieves and removes the head of
38 |java.util.concurrent.BlockingDeque.remove(Object)|Removes the first occurrence
39 |java.util.concurrent.BlockingDeque.removeFirstOccurrence(Object)|Removes the f
40 |java.util.concurrent.BlockingDeque.removeLastOccurrence(Object)|Removes the la
41 |java.util.concurrent.BlockingDeque.size()|Returns the number of elements in th
42 |java.util.concurrent.BlockingDeque.take()|Retrieves and removes the head of th
43 |java.util.concurrent.BlockingDeque.takeFirst()|Retrieves and removes the first
44 |java.util.concurrent.BlockingDeque.takeLast()|Retrieves and removes the last e
46 *java.util.concurrent.BlockingDeque_Description*
48 A (|java.util.Deque|) that additionally supports blocking operations that wait
49 for the deque to become non-empty when retrieving an element, and wait for
50 space to become available in the deque when storing an element.
52 BlockingDeque methods come in four forms, with different ways of handling
53 operations that cannot be satisfied immediately, but may be satisfied at some
54 point in the future: one throws an exception, the second returns a special
55 value (either null or false, depending on the operation), the third blocks the
56 current thread indefinitely until the operation can succeed, and the fourth
57 blocks for only a given maximum time limit before giving up. These methods are
58 summarized in the following table:
66 Throws exception Special value Blocks Times out
68 Insert addFirst(e)(|java.util.concurrent.BlockingDeque|)
69 offerFirst(e)(|java.util.concurrent.BlockingDeque|)
70 putFirst(e)(|java.util.concurrent.BlockingDeque|) offerFirst(e, time,
71 unit)(|java.util.concurrent.BlockingDeque|)
73 Remove removeFirst()(|java.util.concurrent.BlockingDeque|)
74 pollFirst()(|java.util.concurrent.BlockingDeque|)
75 takeFirst()(|java.util.concurrent.BlockingDeque|) pollFirst(time,
76 unit)(|java.util.concurrent.BlockingDeque|)
78 Examine getFirst()(|java.util.concurrent.BlockingDeque|)
79 peekFirst()(|java.util.concurrent.BlockingDeque|) not applicable not applicable
85 Throws exception Special value Blocks Times out
87 Insert addLast(e)(|java.util.concurrent.BlockingDeque|)
88 offerLast(e)(|java.util.concurrent.BlockingDeque|)
89 putLast(e)(|java.util.concurrent.BlockingDeque|) offerLast(e, time,
90 unit)(|java.util.concurrent.BlockingDeque|)
92 Remove removeLast()(|java.util.concurrent.BlockingDeque|)
93 pollLast()(|java.util.concurrent.BlockingDeque|)
94 takeLast()(|java.util.concurrent.BlockingDeque|) pollLast(time,
95 unit)(|java.util.concurrent.BlockingDeque|)
97 Examine getLast()(|java.util.concurrent.BlockingDeque|)
98 peekLast()(|java.util.concurrent.BlockingDeque|) not applicable not applicable
102 Like any (|java.util.concurrent.BlockingQueue|) , a BlockingDeque is thread
103 safe, does not permit null elements, and may (or may not) be
104 capacity-constrained.
106 A BlockingDeque implementation may be used directly as a FIFO BlockingQueue.
107 The methods inherited from the BlockingQueue interface are precisely equivalent
108 to BlockingDeque methods as indicated in the following table:
112 BlockingQueue Method Equivalent BlockingDeque Method
116 add(e)(|java.util.concurrent.BlockingDeque|)
117 addLast(e)(|java.util.concurrent.BlockingDeque|)
119 offer(e)(|java.util.concurrent.BlockingDeque|)
120 offerLast(e)(|java.util.concurrent.BlockingDeque|)
122 put(e)(|java.util.concurrent.BlockingDeque|)
123 putLast(e)(|java.util.concurrent.BlockingDeque|)
125 offer(e, time, unit)(|java.util.concurrent.BlockingDeque|) offerLast(e, time,
126 unit)(|java.util.concurrent.BlockingDeque|)
130 remove()(|java.util.concurrent.BlockingDeque|)
131 removeFirst()(|java.util.concurrent.BlockingDeque|)
133 poll()(|java.util.concurrent.BlockingDeque|)
134 pollFirst()(|java.util.concurrent.BlockingDeque|)
136 take()(|java.util.concurrent.BlockingDeque|)
137 takeFirst()(|java.util.concurrent.BlockingDeque|)
139 poll(time, unit)(|java.util.concurrent.BlockingDeque|) pollFirst(time,
140 unit)(|java.util.concurrent.BlockingDeque|)
144 element()(|java.util.concurrent.BlockingDeque|)
145 getFirst()(|java.util.concurrent.BlockingDeque|)
147 peek()(|java.util.concurrent.BlockingDeque|)
148 peekFirst()(|java.util.concurrent.BlockingDeque|)
152 Memory consistency effects: As with other concurrent collections, actions in a
153 thread prior to placing an object into aBlockingDequehappen-before actions
154 subsequent to the access or removal of that element from theBlockingDequein
157 This interface is a member of the <a
158 href="/../technotes/guides/collections/index.html"> Java Collections Framework.
162 *java.util.concurrent.BlockingDeque.add(E)*
164 public boolean add(E e)
166 Inserts the specified element into the queue represented by this deque (in
167 other words, at the tail of this deque) if it is possible to do so immediately
168 without violating capacity restrictions, returning true upon success and
169 throwing an IllegalStateException if no space is currently available. When
170 using a capacity-restricted deque, it is generally preferable to use
171 offer(|java.util.concurrent.BlockingDeque|) .
173 This method is equivalent to addLast(|java.util.concurrent.BlockingDeque|) .
176 e - the element to add
178 *java.util.concurrent.BlockingDeque.addFirst(E)*
180 public void addFirst(E e)
182 Inserts the specified element at the front of this deque if it is possible to
183 do so immediately without violating capacity restrictions, throwing an
184 IllegalStateException if no space is currently available. When using a
185 capacity-restricted deque, it is generally preferable to use
186 offerFirst(|java.util.concurrent.BlockingDeque|) .
189 e - the element to add
191 *java.util.concurrent.BlockingDeque.addLast(E)*
193 public void addLast(E e)
195 Inserts the specified element at the end of this deque if it is possible to do
196 so immediately without violating capacity restrictions, throwing an
197 IllegalStateException if no space is currently available. When using a
198 capacity-restricted deque, it is generally preferable to use
199 offerLast(|java.util.concurrent.BlockingDeque|) .
202 e - the element to add
204 *java.util.concurrent.BlockingDeque.contains(Object)*
206 public boolean contains(java.lang.Object o)
208 Returns true if this deque contains the specified element. More formally,
209 returns true if and only if this deque contains at least one element e such
213 o - object to be checked for containment in this deque
215 Returns: true if this deque contains the specified element
217 *java.util.concurrent.BlockingDeque.element()*
221 Retrieves, but does not remove, the head of the queue represented by this deque
222 (in other words, the first element of this deque). This method differs from
223 peek(|java.util.concurrent.BlockingDeque|) only in that it throws an exception
224 if this deque is empty.
226 This method is equivalent to getFirst(|java.util.concurrent.BlockingDeque|) .
230 Returns: the head of this deque
232 *java.util.concurrent.BlockingDeque.iterator()*
234 public |java.util.Iterator|<E> iterator()
236 Returns an iterator over the elements in this deque in proper sequence. The
237 elements will be returned in order from first (head) to last (tail).
241 Returns: an iterator over the elements in this deque in proper sequence
243 *java.util.concurrent.BlockingDeque.offer(E)*
245 public boolean offer(E e)
247 Inserts the specified element into the queue represented by this deque (in
248 other words, at the tail of this deque) if it is possible to do so immediately
249 without violating capacity restrictions, returning true upon success and false
250 if no space is currently available. When using a capacity-restricted deque,
251 this method is generally preferable to the
252 (|java.util.concurrent.BlockingDeque|) method, which can fail to insert an
253 element only by throwing an exception.
255 This method is equivalent to offerLast(|java.util.concurrent.BlockingDeque|) .
258 e - the element to add
260 *java.util.concurrent.BlockingDeque.offer(E,long,TimeUnit)*
262 public boolean offer(
265 java.util.concurrent.TimeUnit unit)
266 throws |java.lang.InterruptedException|
268 Inserts the specified element into the queue represented by this deque (in
269 other words, at the tail of this deque), waiting up to the specified wait time
270 if necessary for space to become available.
272 This method is equivalent to offerLast(|java.util.concurrent.BlockingDeque|) .
275 e - the element to add
277 Returns: true if the element was added to this deque, else false
279 *java.util.concurrent.BlockingDeque.offerFirst(E)*
281 public boolean offerFirst(E e)
283 Inserts the specified element at the front of this deque if it is possible to
284 do so immediately without violating capacity restrictions, returning true upon
285 success and false if no space is currently available. When using a
286 capacity-restricted deque, this method is generally preferable to the
287 addFirst(|java.util.concurrent.BlockingDeque|) method, which can fail to insert
288 an element only by throwing an exception.
291 e - the element to add
293 *java.util.concurrent.BlockingDeque.offerFirst(E,long,TimeUnit)*
295 public boolean offerFirst(
298 java.util.concurrent.TimeUnit unit)
299 throws |java.lang.InterruptedException|
301 Inserts the specified element at the front of this deque, waiting up to the
302 specified wait time if necessary for space to become available.
305 e - the element to add
306 timeout - how long to wait before giving up, in units of unit
307 unit - a TimeUnit determining how to interpret the timeout parameter
309 Returns: true if successful, or false if the specified waiting time elapses before space
312 *java.util.concurrent.BlockingDeque.offerLast(E)*
314 public boolean offerLast(E e)
316 Inserts the specified element at the end of this deque if it is possible to do
317 so immediately without violating capacity restrictions, returning true upon
318 success and false if no space is currently available. When using a
319 capacity-restricted deque, this method is generally preferable to the
320 addLast(|java.util.concurrent.BlockingDeque|) method, which can fail to insert
321 an element only by throwing an exception.
324 e - the element to add
326 *java.util.concurrent.BlockingDeque.offerLast(E,long,TimeUnit)*
328 public boolean offerLast(
331 java.util.concurrent.TimeUnit unit)
332 throws |java.lang.InterruptedException|
334 Inserts the specified element at the end of this deque, waiting up to the
335 specified wait time if necessary for space to become available.
338 e - the element to add
339 timeout - how long to wait before giving up, in units of unit
340 unit - a TimeUnit determining how to interpret the timeout parameter
342 Returns: true if successful, or false if the specified waiting time elapses before space
345 *java.util.concurrent.BlockingDeque.peek()*
349 Retrieves, but does not remove, the head of the queue represented by this deque
350 (in other words, the first element of this deque), or returns null if this
353 This method is equivalent to peekFirst(|java.util.concurrent.BlockingDeque|) .
357 Returns: the head of this deque, or null if this deque is empty
359 *java.util.concurrent.BlockingDeque.poll()*
363 Retrieves and removes the head of the queue represented by this deque (in other
364 words, the first element of this deque), or returns null if this deque is
367 This method is equivalent to (|java.util.concurrent.BlockingDeque|) .
371 Returns: the head of this deque, or null if this deque is empty
373 *java.util.concurrent.BlockingDeque.poll(long,TimeUnit)*
377 java.util.concurrent.TimeUnit unit)
378 throws |java.lang.InterruptedException|
380 Retrieves and removes the head of the queue represented by this deque (in other
381 words, the first element of this deque), waiting up to the specified wait time
382 if necessary for an element to become available.
384 This method is equivalent to pollFirst(|java.util.concurrent.BlockingDeque|) .
388 Returns: the head of this deque, or null if the specified waiting time elapses before an
391 *java.util.concurrent.BlockingDeque.pollFirst(long,TimeUnit)*
393 public |E| pollFirst(
395 java.util.concurrent.TimeUnit unit)
396 throws |java.lang.InterruptedException|
398 Retrieves and removes the first element of this deque, waiting up to the
399 specified wait time if necessary for an element to become available.
402 timeout - how long to wait before giving up, in units of unit
403 unit - a TimeUnit determining how to interpret the timeout parameter
405 Returns: the head of this deque, or null if the specified waiting time elapses before an
408 *java.util.concurrent.BlockingDeque.pollLast(long,TimeUnit)*
412 java.util.concurrent.TimeUnit unit)
413 throws |java.lang.InterruptedException|
415 Retrieves and removes the last element of this deque, waiting up to the
416 specified wait time if necessary for an element to become available.
419 timeout - how long to wait before giving up, in units of unit
420 unit - a TimeUnit determining how to interpret the timeout parameter
422 Returns: the tail of this deque, or null if the specified waiting time elapses before an
425 *java.util.concurrent.BlockingDeque.push(E)*
427 public void push(E e)
429 Pushes an element onto the stack represented by this deque. In other words,
430 inserts the element at the front of this deque unless it would violate capacity
433 This method is equivalent to addFirst(|java.util.concurrent.BlockingDeque|) .
437 *java.util.concurrent.BlockingDeque.put(E)*
440 throws |java.lang.InterruptedException|
442 Inserts the specified element into the queue represented by this deque (in
443 other words, at the tail of this deque), waiting if necessary for space to
446 This method is equivalent to putLast(|java.util.concurrent.BlockingDeque|) .
449 e - the element to add
451 *java.util.concurrent.BlockingDeque.putFirst(E)*
453 public void putFirst(E e)
454 throws |java.lang.InterruptedException|
456 Inserts the specified element at the front of this deque, waiting if necessary
457 for space to become available.
460 e - the element to add
462 *java.util.concurrent.BlockingDeque.putLast(E)*
464 public void putLast(E e)
465 throws |java.lang.InterruptedException|
467 Inserts the specified element at the end of this deque, waiting if necessary
468 for space to become available.
471 e - the element to add
473 *java.util.concurrent.BlockingDeque.remove()*
477 Retrieves and removes the head of the queue represented by this deque (in other
478 words, the first element of this deque). This method differs from
479 poll(|java.util.concurrent.BlockingDeque|) only in that it throws an exception
480 if this deque is empty.
482 This method is equivalent to removeFirst(|java.util.concurrent.BlockingDeque|)
487 Returns: the head of the queue represented by this deque
489 *java.util.concurrent.BlockingDeque.remove(Object)*
491 public boolean remove(java.lang.Object o)
493 Removes the first occurrence of the specified element from this deque. If the
494 deque does not contain the element, it is unchanged. More formally, removes the
495 first element e such that o.equals(e) (if such an element exists). Returns true
496 if this deque contained the specified element (or equivalently, if this deque
497 changed as a result of the call).
499 This method is equivalent to
500 removeFirstOccurrence(|java.util.concurrent.BlockingDeque|) .
503 o - element to be removed from this deque, if present
505 Returns: true if this deque changed as a result of the call
507 *java.util.concurrent.BlockingDeque.removeFirstOccurrence(Object)*
509 public boolean removeFirstOccurrence(java.lang.Object o)
511 Removes the first occurrence of the specified element from this deque. If the
512 deque does not contain the element, it is unchanged. More formally, removes the
513 first element e such that o.equals(e) (if such an element exists). Returns true
514 if this deque contained the specified element (or equivalently, if this deque
515 changed as a result of the call).
518 o - element to be removed from this deque, if present
520 Returns: true if an element was removed as a result of this call
522 *java.util.concurrent.BlockingDeque.removeLastOccurrence(Object)*
524 public boolean removeLastOccurrence(java.lang.Object o)
526 Removes the last occurrence of the specified element from this deque. If the
527 deque does not contain the element, it is unchanged. More formally, removes the
528 last element e such that o.equals(e) (if such an element exists). Returns true
529 if this deque contained the specified element (or equivalently, if this deque
530 changed as a result of the call).
533 o - element to be removed from this deque, if present
535 Returns: true if an element was removed as a result of this call
537 *java.util.concurrent.BlockingDeque.size()*
541 Returns the number of elements in this deque.
545 Returns: the number of elements in this deque
547 *java.util.concurrent.BlockingDeque.take()*
550 throws |java.lang.InterruptedException|
552 Retrieves and removes the head of the queue represented by this deque (in other
553 words, the first element of this deque), waiting if necessary until an element
556 This method is equivalent to takeFirst(|java.util.concurrent.BlockingDeque|) .
560 Returns: the head of this deque
562 *java.util.concurrent.BlockingDeque.takeFirst()*
564 public |E| takeFirst()
565 throws |java.lang.InterruptedException|
567 Retrieves and removes the first element of this deque, waiting if necessary
568 until an element becomes available.
572 Returns: the head of this deque
574 *java.util.concurrent.BlockingDeque.takeLast()*
576 public |E| takeLast()
577 throws |java.lang.InterruptedException|
579 Retrieves and removes the last element of this deque, waiting if necessary
580 until an element becomes available.
584 Returns: the tail of this deque