Package org.apache.tomcat.util.threads
Class TaskQueue
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractQueue<E>
-
- java.util.concurrent.LinkedBlockingQueue<Runnable>
-
- org.apache.tomcat.util.threads.TaskQueue
-
- All Implemented Interfaces:
Serializable,Iterable<Runnable>,Collection<Runnable>,BlockingQueue<Runnable>,Queue<Runnable>
public class TaskQueue extends LinkedBlockingQueue<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:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected static StringManagersm
-
Constructor Summary
Constructors Constructor Description TaskQueue()TaskQueue(int capacity)TaskQueue(Collection<? extends Runnable> c)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanforce(Runnable o)Used to add a task to the queue if the task has been rejected by the Executor.booleanoffer(Runnable o)Runnablepoll(long timeout, TimeUnit unit)voidsetParent(ThreadPoolExecutor tp)Runnabletake()-
Methods inherited from class java.util.concurrent.LinkedBlockingQueue
clear, contains, drainTo, drainTo, forEach, iterator, offer, peek, poll, put, remainingCapacity, remove, removeAll, removeIf, retainAll, size, spliterator, toArray, toArray, toString
-
Methods inherited from class java.util.AbstractQueue
add, addAll, element, remove
-
Methods inherited from class java.util.AbstractCollection
containsAll, isEmpty
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.concurrent.BlockingQueue
add
-
Methods inherited from interface java.util.Collection
addAll, containsAll, equals, hashCode, isEmpty, parallelStream, stream, toArray
-
-
-
-
Field Detail
-
sm
protected static final StringManager sm
-
-
Constructor Detail
-
TaskQueue
public TaskQueue()
-
TaskQueue
public TaskQueue(int capacity)
-
TaskQueue
public TaskQueue(Collection<? extends Runnable> c)
-
-
Method Detail
-
setParent
public void setParent(ThreadPoolExecutor tp)
-
force
public boolean force(Runnable o)
Used to add a task to the queue if the task has been rejected by the Executor.- Parameters:
o- The task to add to the queue- Returns:
trueif the task was added to the queue, otherwisefalse
-
offer
public boolean offer(Runnable o)
- Specified by:
offerin interfaceBlockingQueue<Runnable>- Specified by:
offerin interfaceQueue<Runnable>- Overrides:
offerin classLinkedBlockingQueue<Runnable>
-
poll
public Runnable poll(long timeout, TimeUnit unit) throws InterruptedException
- Specified by:
pollin interfaceBlockingQueue<Runnable>- Overrides:
pollin classLinkedBlockingQueue<Runnable>- Throws:
InterruptedException
-
take
public Runnable take() throws InterruptedException
- Specified by:
takein interfaceBlockingQueue<Runnable>- Overrides:
takein classLinkedBlockingQueue<Runnable>- Throws:
InterruptedException
-
-