TaskQueue (Apache Tomcat 10.1.57 API Documentation)
Description: declaration: package: org.apache.tomcat.util.threads, class: TaskQueue

# Class TaskQueue

java.lang.Object
java.util.AbstractCollection<Runnable>
java.util.AbstractQueue<Runnable>
java.util.concurrent.LinkedBlockingQueue<Runnable>
org.apache.tomcat.util.threads.TaskQueue

All Implemented Interfaces:
  `Serializable, Iterable<Runnable>, Collection<Runnable>, BlockingQueue<Runnable>, Queue<Runnable>, RetryableQueue<Runnable>`

public class TaskQueue extends LinkedBlockingQueue<Runnable> implements 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:
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected static final StringManager`
  `sm`
  The 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(Collection<? extends Runnable> c)`
  Constructs a new TaskQueue containing the elements in the given collection.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `force(Runnable o)`
  Used to add a task to the queue if the task has been rejected by the Executor.
  `boolean`
  `offer(Runnable o)`
  `Runnable`
  `poll(long timeout, TimeUnit unit)`
  `void`
  `setParent(ThreadPoolExecutor tp)`
  Sets the parent thread pool executor for this queue.
  `Runnable`
  `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, toString`

  ### Methods inherited from class AbstractQueue

  `add, addAll, element, remove`

  ### Methods inherited from class AbstractCollection

  `containsAll, isEmpty`

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface BlockingQueue

  `add, contains, drainTo, drainTo, offer, put, remainingCapacity, remove`

  ### Methods inherited from interface Collection

  `addAll, clear, containsAll, equals, hashCode, isEmpty, iterator, parallelStream, removeAll, removeIf, retainAll, size, spliterator, stream, toArray, toArray, toArray`

  ### Methods inherited from interface Iterable

  `forEach`

  ### Methods inherited from interface Queue

  `element, peek, poll, remove`

- ## Field Details

  - ### sm

    protected static final StringManager 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

    public TaskQueue(Collection<? extends Runnable> c)
    Constructs a new TaskQueue containing the elements in the given collection.
    Parameters:
      `c` - the collection of initial elements

- ## Method Details

  - ### setParent

    public void setParent(ThreadPoolExecutor tp)
    Sets the parent thread pool executor for this queue.
    Parameters:
      `tp` - the parent executor

  - ### force

    public boolean force(Runnable o)
    Description copied from interface: `RetryableQueue`
    Used to add a task to the queue if the task has been rejected by the Executor.
    Specified by:
      `force` in interface `RetryableQueue<Runnable>`
    Parameters:
      `o` - The task to add to the queue
    Returns:
      `true` if the task was added to the queue, otherwise `false`

  - ### offer

    public boolean offer(Runnable o)
    Specified by:
      `offer` in interface `BlockingQueue<Runnable>`
    Specified by:
      `offer` in interface `Queue<Runnable>`
    Overrides:
      `offer` in class `LinkedBlockingQueue<Runnable>`

  - ### poll

    public Runnable poll(long timeout, TimeUnit unit) throws InterruptedException
    Specified by:
      `poll` in interface `BlockingQueue<Runnable>`
    Overrides:
      `poll` in class `LinkedBlockingQueue<Runnable>`
    Throws:
      `InterruptedException`

  - ### take

    public Runnable take() throws InterruptedException
    Specified by:
      `take` in interface `BlockingQueue<Runnable>`
    Overrides:
      `take` in class `LinkedBlockingQueue<Runnable>`
    Throws:
      `InterruptedException`