Class DynamicQueue<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractQueue<E>
java.util.concurrent.LinkedBlockingQueue<E>
com.j_spaces.kernel.threadpool.queue.DynamicQueue<E>
- All Implemented Interfaces:
Serializable,Iterable<E>,Collection<E>,BlockingQueue<E>,Queue<E>
Much like a
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.
- Since:
- 6.5
- Author:
- moran
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a DynamicQueue with a capacity ofInteger.MAX_VALUE.DynamicQueue(int capacity) Creates a DynamicQueue with the given (fixed) capacity. -
Method Summary
Modifier and TypeMethodDescriptionbooleanInserts the specified element at the tail of this queue if there is at least one available thread to run the current task.voidsetThreadPoolExecutor(ThreadPoolExecutor executor) Sets the executor this queue belongs to.Methods inherited from class java.util.concurrent.LinkedBlockingQueue
clear, contains, drainTo, drainTo, forEach, iterator, offer, peek, poll, poll, put, remainingCapacity, remove, removeAll, removeIf, retainAll, size, spliterator, take, toArray, toArray, toStringMethods inherited from class java.util.AbstractQueue
add, addAll, element, removeMethods inherited from class java.util.AbstractCollection
containsAll, isEmptyMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.concurrent.BlockingQueue
addMethods inherited from interface java.util.Collection
addAll, containsAll, equals, hashCode, isEmpty, parallelStream, stream, toArray
-
Constructor Details
-
DynamicQueue
public DynamicQueue()Creates a DynamicQueue with a capacity ofInteger.MAX_VALUE. -
DynamicQueue
public DynamicQueue(int capacity) Creates a DynamicQueue with the given (fixed) capacity.- Parameters:
capacity- the capacity of this queue.
-
-
Method Details
-
setThreadPoolExecutor
Sets the executor this queue belongs to. -
offer
Inserts the specified element at the tail of this queue if there is at least one available thread to run the current task. If all pool threads are actively busy, it rejects the offer.- Specified by:
offerin interfaceBlockingQueue<E>- Specified by:
offerin interfaceQueue<E>- Overrides:
offerin classLinkedBlockingQueue<E>- Parameters:
o- the element to add.- Returns:
- true if it was possible to add the element to this queue, else false
- See Also:
-