Class QueuedThreadPool

  • All Implemented Interfaces:
    java.util.concurrent.Executor, java.util.concurrent.ThreadFactory, Container, Destroyable, Dumpable, Dumpable.DumpableContainer, LifeCycle, ThreadPool, ThreadPool.SizedThreadPool, TryExecutor
    Direct Known Subclasses:
    MonitoredQueuedThreadPool

    @ManagedObject("A thread pool")
    @Deprecated(since="2021-05-27")
    public class QueuedThreadPool
    extends ContainerLifeCycle
    implements java.util.concurrent.ThreadFactory, ThreadPool.SizedThreadPool, Dumpable, TryExecutor
    Deprecated.
    The Eclipse Jetty and Apache Felix Http Jetty packages are no longer supported.

    A thread pool with a queue of jobs to execute.

    Jetty components that need threads (such as network acceptors and selector) may lease threads from this thread pool using a ThreadPoolBudget; these threads are "active" from the point of view of the thread pool, but not available to run transient jobs such as processing an HTTP request or a WebSocket frame.

    QueuedThreadPool has a ReservedThreadExecutor which leases threads from this pool, but makes them available as if they are "idle" threads.

    QueuedThreadPool therefore has the following fundamental values:

    • threads: the current number of threads. These threads may execute a job (either internal or transient), or may be ready to run (either idle or reserved). This number may grow or shrink as the thread pool grows or shrinks.
    • readyThreads: the current number of threads that are ready to run transient jobs. This number may grow or shrink as the thread pool grows or shrinks.
    • leasedThreads: the number of threads that run internal jobs. This number is typically constant after this thread pool is started.

    Given the definitions above, the most interesting definitions are:

    Other definitions, typically less interesting because they take into account threads that execute internal jobs, or because they don't take into account available reserved threads (that are essentially ready to execute transient jobs), are:

    • Constructor Detail

      • QueuedThreadPool

        public QueuedThreadPool()
        Deprecated.
      • QueuedThreadPool

        public QueuedThreadPool​(@Name("maxThreads")
                                int maxThreads)
        Deprecated.
      • QueuedThreadPool

        public QueuedThreadPool​(@Name("maxThreads")
                                int maxThreads,
                                @Name("minThreads")
                                int minThreads)
        Deprecated.
      • QueuedThreadPool

        public QueuedThreadPool​(@Name("maxThreads")
                                int maxThreads,
                                @Name("minThreads")
                                int minThreads,
                                @Name("queue")
                                java.util.concurrent.BlockingQueue<java.lang.Runnable> queue)
        Deprecated.
      • QueuedThreadPool

        public QueuedThreadPool​(@Name("maxThreads")
                                int maxThreads,
                                @Name("minThreads")
                                int minThreads,
                                @Name("idleTimeout")
                                int idleTimeout)
        Deprecated.
      • QueuedThreadPool

        public QueuedThreadPool​(@Name("maxThreads")
                                int maxThreads,
                                @Name("minThreads")
                                int minThreads,
                                @Name("idleTimeout")
                                int idleTimeout,
                                @Name("queue")
                                java.util.concurrent.BlockingQueue<java.lang.Runnable> queue)
        Deprecated.
      • QueuedThreadPool

        public QueuedThreadPool​(@Name("maxThreads")
                                int maxThreads,
                                @Name("minThreads")
                                int minThreads,
                                @Name("idleTimeout")
                                int idleTimeout,
                                @Name("queue")
                                java.util.concurrent.BlockingQueue<java.lang.Runnable> queue,
                                @Name("threadGroup")
                                java.lang.ThreadGroup threadGroup)
        Deprecated.
      • QueuedThreadPool

        public QueuedThreadPool​(@Name("maxThreads")
                                int maxThreads,
                                @Name("minThreads")
                                int minThreads,
                                @Name("idleTimeout")
                                int idleTimeout,
                                @Name("reservedThreads")
                                int reservedThreads,
                                @Name("queue")
                                java.util.concurrent.BlockingQueue<java.lang.Runnable> queue,
                                @Name("threadGroup")
                                java.lang.ThreadGroup threadGroup)
        Deprecated.
      • QueuedThreadPool

        public QueuedThreadPool​(@Name("maxThreads")
                                int maxThreads,
                                @Name("minThreads")
                                int minThreads,
                                @Name("idleTimeout")
                                int idleTimeout,
                                @Name("reservedThreads")
                                int reservedThreads,
                                @Name("queue")
                                java.util.concurrent.BlockingQueue<java.lang.Runnable> queue,
                                @Name("threadGroup")
                                java.lang.ThreadGroup threadGroup,
                                @Name("threadFactory")
                                java.util.concurrent.ThreadFactory threadFactory)
        Deprecated.
    • Method Detail

      • setThreadPoolBudget

        public void setThreadPoolBudget​(ThreadPoolBudget budget)
        Deprecated.
      • getIdleTimeout

        @ManagedAttribute("maximum time a thread may be idle in ms")
        public int getIdleTimeout()
        Deprecated.
        Returns:
        the maximum thread idle time in ms
      • setIdleTimeout

        public void setIdleTimeout​(int idleTimeout)
        Deprecated.

        Set the maximum thread idle time in ms.

        Threads that are idle for longer than this period may be stopped.

        Parameters:
        idleTimeout - the maximum thread idle time in ms
      • setMaxThreads

        public void setMaxThreads​(int maxThreads)
        Deprecated.
        Specified by:
        setMaxThreads in interface ThreadPool.SizedThreadPool
        Parameters:
        maxThreads - the maximum number of threads
      • setMinThreads

        public void setMinThreads​(int minThreads)
        Deprecated.
        Specified by:
        setMinThreads in interface ThreadPool.SizedThreadPool
        Parameters:
        minThreads - minimum number of threads
      • getReservedThreads

        @ManagedAttribute("number of configured reserved threads or -1 for heuristic")
        public int getReservedThreads()
        Deprecated.
        Returns:
        number of reserved threads or -1 for heuristically determined
      • setReservedThreads

        public void setReservedThreads​(int reservedThreads)
        Deprecated.
        Parameters:
        reservedThreads - number of reserved threads or -1 for heuristically determined
      • getName

        @ManagedAttribute("name of the thread pool")
        public java.lang.String getName()
        Deprecated.
        Returns:
        the name of the this thread pool
      • setName

        public void setName​(java.lang.String name)
        Deprecated.

        Sets the name of this thread pool, used as a prefix for the thread names.

        Parameters:
        name - the name of the this thread pool
      • getThreadsPriority

        @ManagedAttribute("priority of threads in the pool")
        public int getThreadsPriority()
        Deprecated.
        Returns:
        the priority of the pool threads
      • setThreadsPriority

        public void setThreadsPriority​(int priority)
        Deprecated.
        Parameters:
        priority - the priority of the pool threads
      • isDaemon

        @ManagedAttribute("thread pool uses daemon threads")
        public boolean isDaemon()
        Deprecated.
        Returns:
        whether to use daemon threads
        See Also:
        Thread.isDaemon()
      • setDaemon

        public void setDaemon​(boolean daemon)
        Deprecated.
        Parameters:
        daemon - whether to use daemon threads
        See Also:
        Thread.setDaemon(boolean)
      • isDetailedDump

        @ManagedAttribute("reports additional details in the dump")
        public boolean isDetailedDump()
        Deprecated.
      • setDetailedDump

        public void setDetailedDump​(boolean detailedDump)
        Deprecated.
      • getLowThreadsThreshold

        @ManagedAttribute("threshold at which the pool is low on threads")
        public int getLowThreadsThreshold()
        Deprecated.
      • setLowThreadsThreshold

        public void setLowThreadsThreshold​(int lowThreadsThreshold)
        Deprecated.
      • getQueueSize

        @ManagedAttribute("size of the job queue")
        public int getQueueSize()
        Deprecated.
        Returns:
        the number of jobs in the queue waiting for a thread
      • getThreads

        @ManagedAttribute("number of threads in the pool")
        public int getThreads()
        Deprecated.

        The fundamental value that represents the number of threads currently known by this thread pool.

        This value includes threads that have been leased to internal components, idle threads, reserved threads and threads that are executing transient jobs.

        Specified by:
        getThreads in interface ThreadPool
        Returns:
        the number of threads currently known to the pool
        See Also:
        getReadyThreads(), getLeasedThreads()
      • getReadyThreads

        @ManagedAttribute("number of threads ready to execute transient jobs")
        public int getReadyThreads()
        Deprecated.

        The fundamental value that represents the number of threads ready to execute transient jobs.

        Returns:
        the number of threads ready to execute transient jobs
        See Also:
        getThreads(), getLeasedThreads(), getUtilizedThreads()
      • getLeasedThreads

        @ManagedAttribute("number of threads used by internal components")
        public int getLeasedThreads()
        Deprecated.

        The fundamental value that represents the number of threads that are leased to internal components, and therefore cannot be used to execute transient jobs.

        Returns:
        the number of threads currently used by internal components
        See Also:
        getThreads(), getReadyThreads()
      • getMaxLeasedThreads

        @ManagedAttribute("maximum number of threads leased to internal components")
        public int getMaxLeasedThreads()
        Deprecated.

        The maximum number of threads that are leased to internal components, as some component may allocate its threads lazily.

        Returns:
        the maximum number of threads leased by internal components
        See Also:
        getLeasedThreads()
      • getIdleThreads

        @ManagedAttribute("number of idle threads but not reserved")
        public int getIdleThreads()
        Deprecated.

        The number of idle threads, but without including reserved threads.

        Prefer getReadyThreads() for a better representation of "threads ready to execute transient jobs".

        Specified by:
        getIdleThreads in interface ThreadPool
        Returns:
        the number of idle threads but not reserved
        See Also:
        getReadyThreads()
      • getBusyThreads

        @ManagedAttribute("number of threads executing internal and transient jobs")
        public int getBusyThreads()
        Deprecated.

        The number of threads executing internal and transient jobs.

        Prefer getUtilizedThreads() for a better representation of "threads executing transient jobs".

        Returns:
        the number of threads executing internal and transient jobs
        See Also:
        getUtilizedThreads()
      • getUtilizedThreads

        @ManagedAttribute("number of threads executing transient jobs")
        public int getUtilizedThreads()
        Deprecated.

        The number of threads executing transient jobs.

        Returns:
        the number of threads executing transient jobs
        See Also:
        getReadyThreads()
      • getMaxAvailableThreads

        @ManagedAttribute("maximum number of threads available to run transient jobs")
        public int getMaxAvailableThreads()
        Deprecated.

        The maximum number of threads available to run transient jobs.

        Returns:
        the maximum number of threads available to run transient jobs
      • getUtilizationRate

        @ManagedAttribute("utilization rate of threads executing transient jobs")
        public double getUtilizationRate()
        Deprecated.

        The rate between the number of utilized threads and the maximum number of utilizable threads.

        A value of 0.0D means that the thread pool is not utilized, while a value of 1.0D means that the thread pool is fully utilized to execute transient jobs.

        Returns:
        the utilization rate of threads executing transient jobs
      • isLowOnThreads

        @ManagedAttribute(value="thread pool is low on threads",
                          readonly=true)
        public boolean isLowOnThreads()
        Deprecated.

        Returns whether this thread pool is low on threads.

        The current formula is:

         maxThreads - threads + readyThreads - queueSize <= lowThreadsThreshold
         
        Specified by:
        isLowOnThreads in interface ThreadPool
        Returns:
        whether the pool is low on threads
        See Also:
        getLowThreadsThreshold()
      • execute

        public void execute​(java.lang.Runnable job)
        Deprecated.
        Specified by:
        execute in interface java.util.concurrent.Executor
        Specified by:
        execute in interface TryExecutor
      • tryExecute

        public boolean tryExecute​(java.lang.Runnable task)
        Deprecated.
        Description copied from interface: TryExecutor
        Attempt to execute a task.
        Specified by:
        tryExecute in interface TryExecutor
        Parameters:
        task - The task to be executed
        Returns:
        True IFF the task has been given directly to a thread to execute. The task cannot be queued pending the later availability of a Thread.
      • join

        public void join()
                  throws java.lang.InterruptedException
        Deprecated.
        Blocks until the thread pool is stopped.
        Specified by:
        join in interface ThreadPool
        Throws:
        java.lang.InterruptedException - if thread was interrupted
      • newThread

        public java.lang.Thread newThread​(java.lang.Runnable runnable)
        Deprecated.
        Specified by:
        newThread in interface java.util.concurrent.ThreadFactory
      • dump

        public void dump​(java.lang.Appendable out,
                         java.lang.String indent)
                  throws java.io.IOException
        Deprecated.
        Description copied from interface: Dumpable
        Dump this object (and children) into an Appendable using the provided indent after any new lines. The indent should not be applied to the first object dumped.
        Specified by:
        dump in interface Dumpable
        Overrides:
        dump in class ContainerLifeCycle
        Parameters:
        out - The appendable to dump to
        indent - The indent to apply after any new lines.
        Throws:
        java.io.IOException - if unable to write to Appendable
      • setQueue

        @Deprecated
        public void setQueue​(java.util.concurrent.BlockingQueue<java.lang.Runnable> queue)
        Deprecated.
        pass the queue to the constructor instead
        Parameters:
        queue - the job queue
      • interruptThread

        @ManagedOperation("interrupts a pool thread")
        public boolean interruptThread​(@Name("id")
                                       long id)
        Deprecated.
        Parameters:
        id - the thread ID to interrupt.
        Returns:
        true if the thread was found and interrupted.
      • dumpThread

        @ManagedOperation("dumps a pool thread stack")
        public java.lang.String dumpThread​(@Name("id")
                                           long id)
        Deprecated.
        Parameters:
        id - the thread ID to interrupt.
        Returns:
        the stack frames dump