Class TaskQueue
- All Implemented Interfaces:
Serializable, Iterable<Runnable>, Collection<Runnable>, BlockingQueue<Runnable>, Queue<Runnable>, RetryableQueue<Runnable>
As task queue specifically designed to run with a thread pool executor. The task queue is optimised to properly
utilize threads within a thread pool executor. If you use a normal queue, the executor will spawn threads when there
are idle threads and you won't be able to force items onto the queue itself.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final StringManagerThe string manager for this package. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new TaskQueue with default capacity.TaskQueue(int capacity) Constructs a new TaskQueue with the given capacity.TaskQueue(Collection<? extends Runnable> c) Constructs a new TaskQueue containing the elements in the given collection. -
Method Summary
Modifier and TypeMethodDescriptionbooleanUsed to add a task to the queue if the task has been rejected by the Executor.booleanvoidSets the parent thread pool executor for this queue.take()Methods inherited from class LinkedBlockingQueue
clear, contains, drainTo, drainTo, forEach, iterator, offer, peek, poll, put, remainingCapacity, remove, removeAll, removeIf, retainAll, size, spliterator, toArray, toArray, toStringMethods inherited from class AbstractQueue
add, addAll, element, removeMethods inherited from class AbstractCollection
containsAll, isEmptyMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface BlockingQueue
add, contains, drainTo, drainTo, offer, put, remainingCapacity, removeMethods inherited from interface Collection
addAll, clear, containsAll, equals, hashCode, isEmpty, iterator, parallelStream, removeAll, removeIf, retainAll, size, spliterator, stream, toArray, toArray, toArray
-
Field Details
-
sm
The string manager for this package.
-
-
Constructor Details
-
TaskQueue
public TaskQueue()Constructs a new TaskQueue with default capacity. -
TaskQueue
public TaskQueue(int capacity) Constructs a new TaskQueue with the given capacity.- Parameters:
capacity- the queue capacity
-
TaskQueue
Constructs a new TaskQueue containing the elements in the given collection.- Parameters:
c- the collection of initial elements
-
-
Method Details
-
setParent
Sets the parent thread pool executor for this queue.- Parameters:
tp- the parent executor
-
force
Description copied from interface:RetryableQueueUsed to add a task to the queue if the task has been rejected by the Executor.- Specified by:
forcein interfaceRetryableQueue<Runnable>- Parameters:
o- The task to add to the queue- Returns:
trueif the task was added to the queue, otherwisefalse
-
offer
- Specified by:
offerin interfaceBlockingQueue<Runnable>- Specified by:
offerin interfaceQueue<Runnable>- Overrides:
offerin classLinkedBlockingQueue<Runnable>
-
poll
- Specified by:
pollin interfaceBlockingQueue<Runnable>- Overrides:
pollin classLinkedBlockingQueue<Runnable>- Throws:
InterruptedException
-
take
- Specified by:
takein interfaceBlockingQueue<Runnable>- Overrides:
takein classLinkedBlockingQueue<Runnable>- Throws:
InterruptedException
-