Class 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>

    public class TaskQueue
    extends java.util.concurrent.LinkedBlockingQueue<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 StringManager sm  
    • Constructor Summary

      Constructors 
      Constructor Description
      TaskQueue()  
      TaskQueue​(int capacity)  
      TaskQueue​(java.util.Collection<? extends java.lang.Runnable> c)  
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      boolean force​(java.lang.Runnable o)
      Used to add a task to the queue if the task has been rejected by the Executor.
      boolean force​(java.lang.Runnable o, long timeout, java.util.concurrent.TimeUnit unit)
      Deprecated.
      Unused.
      boolean offer​(java.lang.Runnable o)  
      java.lang.Runnable poll​(long timeout, java.util.concurrent.TimeUnit unit)  
      void setParent​(ThreadPoolExecutor tp)  
      java.lang.Runnable take()  
      • 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
      • Methods inherited from interface java.util.Queue

        element, remove
    • Constructor Detail

      • TaskQueue

        public TaskQueue()
      • TaskQueue

        public TaskQueue​(int capacity)
      • TaskQueue

        public TaskQueue​(java.util.Collection<? extends java.lang.Runnable> c)
    • Method Detail

      • force

        public boolean force​(java.lang.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:
        true if the task was added to the queue, otherwise false
      • force

        @Deprecated
        public boolean force​(java.lang.Runnable o,
                             long timeout,
                             java.util.concurrent.TimeUnit unit)
                      throws java.lang.InterruptedException
        Deprecated.
        Unused. Will be removed in Tomcat 10.1.x.
        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
        timeout - The timeout to use when adding the task
        unit - The units in which the timeout is expressed
        Returns:
        true if the task was added to the queue, otherwise false
        Throws:
        java.lang.InterruptedException - If the call is interrupted before the timeout expires
      • offer

        public boolean offer​(java.lang.Runnable o)
        Specified by:
        offer in interface java.util.concurrent.BlockingQueue<java.lang.Runnable>
        Specified by:
        offer in interface java.util.Queue<java.lang.Runnable>
        Overrides:
        offer in class java.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:
        poll in interface java.util.concurrent.BlockingQueue<java.lang.Runnable>
        Overrides:
        poll in class java.util.concurrent.LinkedBlockingQueue<java.lang.Runnable>
        Throws:
        java.lang.InterruptedException
      • take

        public java.lang.Runnable take()
                                throws java.lang.InterruptedException
        Specified by:
        take in interface java.util.concurrent.BlockingQueue<java.lang.Runnable>
        Overrides:
        take in class java.util.concurrent.LinkedBlockingQueue<java.lang.Runnable>
        Throws:
        java.lang.InterruptedException