public class DynamicQueue<E> extends LinkedBlockingQueue<E>
SynchronousQueue
which acts as a rendezvous channel. It is well suited for
handoff designs, in which a tasks is only queued if there is an available thread to pick it up.
This queue is correlated with a thread-pool, and allows insertions to the queue only if there
is a free thread that can poll this task. Otherwise, the task is rejected and the decision is
left up to one of the RejectedExecutionHandler
policies:
ForceQueuePolicy
- forces the queue to accept the rejected task. TimedBlockingPolicy
- waits for a given time for the task to be executed.Constructor and Description |
---|
DynamicQueue()
Creates a DynamicQueue with a capacity of
Integer.MAX_VALUE . |
DynamicQueue(int capacity)
Creates a DynamicQueue with the given (fixed) capacity.
|
Modifier and Type | Method and Description |
---|---|
boolean |
offer(E o)
Inserts the specified element at the tail of this queue if there is at least one available
thread to run the current task.
|
void |
setThreadPoolExecutor(ThreadPoolExecutor executor)
Sets the executor this queue belongs to.
|
clear, contains, drainTo, drainTo, iterator, offer, peek, poll, poll, put, remainingCapacity, remove, size, spliterator, take, toArray, toArray, toString
add, addAll, element, remove
containsAll, isEmpty, removeAll, retainAll
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
add
addAll, containsAll, equals, hashCode, isEmpty, parallelStream, removeAll, removeIf, retainAll, stream
public DynamicQueue()
Integer.MAX_VALUE
.public DynamicQueue(int capacity)
capacity
- the capacity of this queue.public void setThreadPoolExecutor(ThreadPoolExecutor executor)
public boolean offer(E o)
offer
in interface BlockingQueue<E>
offer
in interface Queue<E>
offer
in class LinkedBlockingQueue<E>
o
- the element to add.ThreadPoolExecutor.execute(Runnable)
Copyright © GigaSpaces.