| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
DelayQueue q = new DelayQueue();
Based on 21 examples
public class DelayQueue extends AbstractQueue implements BlockingQueue
An unbounded {@linkplain BlockingQueue blocking queue} of Delayed elements, in which an element can only be taken when its delay has expired. The head of the queue is that Delayed element whose delay expired furthest in the past. If no delay has expired there is no head and poll will return null. Expiration occurs when an element's getDelay(TimeUnit.NANOSECONDS) method returns a value less than or equal to zero. Even though unexpired elements cannot be removed using take or poll, they are otherwise treated as normal elements. For example, the size method returns the count of both expired and unexpired elements. This queue does not permit null elements.
This class and its iterator implement all of the optional methods of the {@link Collection} and {@link Iterator} interfaces.
This class is a member of the Java Collections Framework.
Constructor Summary | |
---|---|
Creates a new DelayQueue that is initially empty. |
|
Creates a DelayQueue initially containing the elements of the given collection of java.util.concurrent.Delayed instances. |
Method Summary | |
---|---|
boolean |
Inserts the specified element into this delay queue. |
void |
clear() Atomically removes all of the elements from this delay queue. |
int |
|
int |
drainTo(Collection c, int maxElements) |
Iterator |
iterator() Returns an iterator over all the elements (both expired and unexpired) in this queue. |
boolean |
Inserts the specified element into this delay queue. |
boolean |
Inserts the specified element into this delay queue. |
Delayed |
peek() Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty. |
Delayed |
poll() Retrieves and removes the head of this queue, or returns null if this queue has no elements with an expired delay. |
Delayed |
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 |
Inserts the specified element into this delay queue. |
int |
Always returns Integer.MAX_VALUE because a DelayQueue is not capacity constrained. |
boolean |
Removes a single instance of the specified element from this queue, if it is present, whether or not it has expired. |
int |
size() |
Delayed |
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. |
Object[] |
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 class java.util.AbstractQueue |
---|
add, addAll, clear, element, remove |
Methods inherited from class java.util.AbstractCollection |
---|
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DelayQueue()
public DelayQueue(Collection c)
c
- the collection of elements to initially containMethod Detail |
---|
public boolean add(Delayed e)
add
in class AbstractQueue
e
- the element to addpublic void clear()
clear
in class AbstractQueue
public int drainTo(Collection c)
c
public int drainTo(Collection c, int maxElements)
c
maxElements
public Iterator iterator()
iterator
in class AbstractCollection
public boolean offer(Delayed e)
e
- the element to addpublic boolean offer(Delayed e, long timeout, TimeUnit unit)
e
- the element to addtimeout
- This parameter is ignored as the method never blocksunit
- This parameter is ignored as the method never blockspublic Delayed peek()
public Delayed poll()
public Delayed poll(long timeout, TimeUnit unit) throws InterruptedException
timeout
unit
InterruptedException
- {@inheritDoc}public void put(Delayed e)
e
- the element to addpublic int remainingCapacity()
public boolean remove(Object o)
remove
in class AbstractCollection
o
public int size()
size
in class AbstractCollection
public Delayed take() throws InterruptedException
InterruptedException
- {@inheritDoc}public Object[] toArray()
The returned array will be "safe" in that no references to it are maintained by this queue. (In other words, this method must allocate a new array). The caller is thus free to modify the returned array.
This method acts as bridge between array-based and collection-based APIs.
toArray
in class AbstractCollection
public Object[] toArray(Object[] a)
If this queue fits in the specified array with room to spare (i.e., the array has more elements than this queue), the element in the array immediately following the end of the queue is set to null.
Like the {@link #toArray()} method, this method acts as bridge between array-based and collection-based APIs. Further, this method allows precise control over the runtime type of the output array, and may, under certain circumstances, be used to save allocation costs.
The following code can be used to dump a delay queue into a newly allocated array of Delayed:
Delayed[] a = q.toArray(new Delayed[0]);Note that toArray(new Object[0]) is identical in function to toArray().
toArray
in class AbstractCollection
a
- the array into which the elements of the queue are to
be stored, if it is big enough; otherwise, a new array of the
same runtime type is allocated for this purpose
| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |