Package org.apache.tomcat.util.threads
Class TaskQueue
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractQueue<E>
-
- java.util.concurrent.LinkedBlockingQueue<java.lang.Runnable>
-
- org.apache.tomcat.util.threads.TaskQueue
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Iterable<java.lang.Runnable>,java.util.Collection<java.lang.Runnable>,java.util.concurrent.BlockingQueue<java.lang.Runnable>,java.util.Queue<java.lang.Runnable>,RetryableQueue<java.lang.Runnable>
public class TaskQueue extends java.util.concurrent.LinkedBlockingQueue<java.lang.Runnable> implements RetryableQueue<java.lang.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 StringManagersmThe string manager for this package.
-
Constructor Summary
Constructors Constructor Description TaskQueue()Constructs a new TaskQueue with default capacity.TaskQueue(int capacity)Constructs a new TaskQueue with the given capacity.TaskQueue(java.util.Collection<? extends java.lang.Runnable> c)Constructs a new TaskQueue containing the elements in the given collection.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleanforce(java.lang.Runnable o)Used to add a task to the queue if the task has been rejected by the Executor.booleanforce(java.lang.Runnable o, long timeout, java.util.concurrent.TimeUnit unit)Deprecated.booleanoffer(java.lang.Runnable o)java.lang.Runnablepoll(long timeout, java.util.concurrent.TimeUnit unit)voidsetParent(ThreadPoolExecutor tp)Sets the parent thread pool executor for this queue.java.lang.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.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.concurrent.BlockingQueue
add, contains, drainTo, drainTo, offer, put, remainingCapacity, remove
-
-
-
-
Field Detail
-
sm
protected static final StringManager sm
The string manager for this package.
-
-
Constructor Detail
-
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
public TaskQueue(java.util.Collection<? extends java.lang.Runnable> c)
Constructs a new TaskQueue containing the elements in the given collection.- Parameters:
c- the collection of initial elements
-
-
Method Detail
-
setParent
public void setParent(ThreadPoolExecutor tp)
Sets the parent thread pool executor for this queue.- Parameters:
tp- the parent executor
-
force
public boolean force(java.lang.Runnable o)
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<java.lang.Runnable>- Parameters:
o- The task to add to the queue- Returns:
trueif the task was added to the queue, otherwisefalse
-
force
@Deprecated public boolean force(java.lang.Runnable o, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedExceptionDeprecated.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<java.lang.Runnable>- Parameters:
o- The task to add to the queuetimeout- The timeout to use when adding the taskunit- The units in which the timeout is expressed- Returns:
trueif the task was added to the queue, otherwisefalse- Throws:
java.lang.InterruptedException- If the call is interrupted before the timeout expires
-
offer
public boolean offer(java.lang.Runnable o)
- Specified by:
offerin interfacejava.util.concurrent.BlockingQueue<java.lang.Runnable>- Specified by:
offerin interfacejava.util.Queue<java.lang.Runnable>- Overrides:
offerin classjava.util.concurrent.LinkedBlockingQueue<java.lang.Runnable>
-
poll
public java.lang.Runnable poll(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException- Specified by:
pollin interfacejava.util.concurrent.BlockingQueue<java.lang.Runnable>- Overrides:
pollin classjava.util.concurrent.LinkedBlockingQueue<java.lang.Runnable>- Throws:
java.lang.InterruptedException
-
take
public java.lang.Runnable take() throws java.lang.InterruptedException- Specified by:
takein interfacejava.util.concurrent.BlockingQueue<java.lang.Runnable>- Overrides:
takein classjava.util.concurrent.LinkedBlockingQueue<java.lang.Runnable>- Throws:
java.lang.InterruptedException
-
-