GeezerVison is showing docs.oracle.com — DelayQueue (Java Platform SE 8 )
Java™ Platform Standard Ed. 8
compact1, compact2, compact3
java.util.concurrent
Class DelayQueue<E extends Delayed>
-
-
Constructor Summary
Constructors
| Constructor |
Description |
DelayQueue() |
Creates a new DelayQueue that is initially empty.
|
DelayQueue(Collection<? extends E> c) |
Creates a DelayQueue initially containing the elements of the
given collection of Delayed instances.
|
-
Method Summary
All Methods Instance Methods Concrete Methods
| Modifier and Type |
Method |
Description |
boolean |
add(E e) |
Inserts the specified element into this delay queue.
|
void |
clear() |
Atomically removes all of the elements from this delay queue.
|
int |
drainTo(Collection<? super E> c) |
Removes all available elements from this queue and adds them
to the given collection.
|
int |
drainTo(Collection<? super E> c,
int maxElements) |
Removes at most the given number of available elements from
this queue and adds them to the given collection.
|
Iterator<E> |
iterator() |
Returns an iterator over all the elements (both expired and
unexpired) in this queue.
|
boolean |
offer(E e) |
Inserts the specified element into this delay queue.
|
boolean |
offer(E e,
long timeout,
TimeUnit unit) |
Inserts the specified element into this delay queue.
|
E |
peek() |
Retrieves, but does not remove, the head of this queue, or
returns null if this queue is empty.
|
E |
poll() |
Retrieves and removes the head of this queue, or returns null
if this queue has no elements with an expired delay.
|
E |
poll(long timeout,
TimeUnit unit) |
Retrieves and removes the head of this queue, waiting if necessary
until an element with an expired delay is available on this queue,
or the specified wait time expires.
|
void |
put(E e) |
Inserts the specified element into this delay queue.
|
int |
remainingCapacity() |
Always returns Integer.MAX_VALUE because
a DelayQueue is not capacity constrained.
|
boolean |
remove(Object o) |
Removes a single instance of the specified element from this
queue, if it is present, whether or not it has expired.
|
int |
size() |
Returns the number of elements in this collection.
|
E |
take() |
Retrieves and removes the head of this queue, waiting if necessary
until an element with an expired delay is available on this queue.
|
Object[] |
toArray() |
Returns an array containing all of the elements in this queue.
|
<T> T[] |
toArray(T[] a) |
Returns an array containing all of the elements in this queue; the
runtime type of the returned array is that of the specified array.
|
-
Methods inherited from interface java.util.Collection
addAll, containsAll, equals, hashCode, isEmpty, parallelStream, removeAll, removeIf, retainAll, spliterator, stream
-
-
Method Detail
-
offer
public boolean offer(E e,
long timeout,
TimeUnit unit)
Inserts the specified element into this delay queue. As the queue is
unbounded this method will never block.
- Specified by:
offer in interface BlockingQueue<E extends Delayed>
- Parameters:
e - the element to add
timeout - This parameter is ignored as the method never blocks
unit - This parameter is ignored as the method never blocks
- Returns:
true
- Throws:
NullPointerException - if the specified element is null
-
take
public E take()
throws InterruptedException
Retrieves and removes the head of this queue, waiting if necessary
until an element with an expired delay is available on this queue.
- Specified by:
take in interface BlockingQueue<E extends Delayed>
- Returns:
- the head of this queue
- Throws:
InterruptedException - if interrupted while waiting
-
poll
public E poll(long timeout,
TimeUnit unit)
throws InterruptedException
Retrieves and removes the head of this queue, waiting if necessary
until an element with an expired delay is available on this queue,
or the specified wait time expires.
- Specified by:
poll in interface BlockingQueue<E extends Delayed>
- Parameters:
timeout - how long to wait before giving up, in units of
unit
unit - a TimeUnit determining how to interpret the
timeout parameter
- Returns:
- the head of this queue, or
null if the
specified waiting time elapses before an element with
an expired delay becomes available
- Throws:
InterruptedException - if interrupted while waiting
-
peek
public E peek()
Retrieves, but does not remove, the head of this queue, or
returns null if this queue is empty. Unlike
poll, if no expired elements are available in the queue,
this method returns the element that will expire next,
if one exists.
- Specified by:
peek in interface Queue<E extends Delayed>
- Returns:
- the head of this queue, or
null if this
queue is empty
-
drainTo
public int drainTo(Collection<? super E> c)
Removes all available elements from this queue and adds them
to the given collection. This operation may be more
efficient than repeatedly polling this queue. A failure
encountered while attempting to add elements to
collection c may result in elements being in neither,
either or both collections when the associated exception is
thrown. Attempts to drain a queue to itself result in
IllegalArgumentException. Further, the behavior of
this operation is undefined if the specified collection is
modified while the operation is in progress.
- Specified by:
drainTo in interface BlockingQueue<E extends Delayed>
- Parameters:
c - the collection to transfer elements into
- Returns:
- the number of elements transferred
- Throws:
UnsupportedOperationException - if addition of elements
is not supported by the specified collection
ClassCastException - if the class of an element of this queue
prevents it from being added to the specified collection
NullPointerException - if the specified collection is null
IllegalArgumentException - if the specified collection is this
queue, or some property of an element of this queue prevents
it from being added to the specified collection
-
drainTo
public int drainTo(Collection<? super E> c,
int maxElements)
Removes at most the given number of available elements from
this queue and adds them to the given collection. A failure
encountered while attempting to add elements to
collection c may result in elements being in neither,
either or both collections when the associated exception is
thrown. Attempts to drain a queue to itself result in
IllegalArgumentException. Further, the behavior of
this operation is undefined if the specified collection is
modified while the operation is in progress.
- Specified by:
drainTo in interface BlockingQueue<E extends Delayed>
- Parameters:
c - the collection to transfer elements into
maxElements - the maximum number of elements to transfer
- Returns:
- the number of elements transferred
- Throws:
UnsupportedOperationException - if addition of elements
is not supported by the specified collection
ClassCastException - if the class of an element of this queue
prevents it from being added to the specified collection
NullPointerException - if the specified collection is null
IllegalArgumentException - if the specified collection is this
queue, or some property of an element of this queue prevents
it from being added to the specified collection
-
remove
public boolean remove(Object o)
Removes a single instance of the specified element from this
queue, if it is present, whether or not it has expired.
- Specified by:
remove in interface Collection<E extends Delayed>
- Specified by:
remove in interface BlockingQueue<E extends Delayed>
- Overrides:
remove in class AbstractCollection<E extends Delayed>
- Parameters:
o - element to be removed from this collection, if present
- Returns:
- true if an element was removed as a result of this call
Java™ Platform Standard Ed. 8
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, 2026, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
|