Class ExecutorThreadPool

All Implemented Interfaces:
Executor, Container, Destroyable, Dumpable, Dumpable.DumpableContainer, LifeCycle, ThreadPool, ThreadPool.SizedThreadPool, TryExecutor, VirtualThreads.Configurable

@ManagedObject("A thread pool") public class ExecutorThreadPool extends ContainerLifeCycle implements ThreadPool.SizedThreadPool, TryExecutor, VirtualThreads.Configurable
  • Constructor Details

    • ExecutorThreadPool

      public ExecutorThreadPool()
    • ExecutorThreadPool

      public ExecutorThreadPool(int maxThreads)
    • ExecutorThreadPool

      public ExecutorThreadPool(int maxThreads, int minThreads)
    • ExecutorThreadPool

      public ExecutorThreadPool(int maxThreads, int minThreads, BlockingQueue<Runnable> queue)
    • ExecutorThreadPool

      public ExecutorThreadPool(ThreadPoolExecutor executor)
    • ExecutorThreadPool

      public ExecutorThreadPool(ThreadPoolExecutor executor, int reservedThreads)
    • ExecutorThreadPool

      public ExecutorThreadPool(ThreadPoolExecutor executor, int reservedThreads, ThreadGroup group)
  • Method Details

    • getName

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

      public void setName(String name)
      Parameters:
      name - the name of this thread pool, used to name threads
    • getMinThreads

      @ManagedAttribute("minimum number of threads in the pool") public int getMinThreads()
      Specified by:
      getMinThreads in interface ThreadPool.SizedThreadPool
      Returns:
      the minimum number of threads
    • setMinThreads

      public void setMinThreads(int threads)
      Specified by:
      setMinThreads in interface ThreadPool.SizedThreadPool
      Parameters:
      threads - the minimum number of threads
    • getMaxThreads

      @ManagedAttribute("maximum number of threads in the pool") public int getMaxThreads()
      Specified by:
      getMaxThreads in interface ThreadPool.SizedThreadPool
      Returns:
      the maximum number of threads
    • setMaxThreads

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

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

      public void setIdleTimeout(int idleTimeout)

      Sets 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.
      See Also:
    • getReservedThreads

      @ManagedAttribute("the number of reserved threads in the pool") public int getReservedThreads()
      Returns:
      number of reserved threads or -1 to indicate that the number is heuristically determined
      See Also:
    • setReservedThreads

      public void setReservedThreads(int reservedThreads)
      Sets the number of reserved threads.
      Parameters:
      reservedThreads - number of reserved threads or -1 to determine the number heuristically
      See Also:
    • setThreadsPriority

      public void setThreadsPriority(int priority)
    • getThreadsPriority

      public int getThreadsPriority()
    • isDaemon

      @ManagedAttribute("whether this thread pool uses daemon threads") public boolean isDaemon()
      Returns:
      whether this thread pool uses daemon threads
      See Also:
    • setDaemon

      public void setDaemon(boolean daemon)
      Parameters:
      daemon - whether this thread pool uses daemon threads
      See Also:
    • isDetailedDump

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

      public void setDetailedDump(boolean detailedDump)
    • getThreads

      @ManagedAttribute("number of threads in the pool") public int getThreads()
      Specified by:
      getThreads in interface ThreadPool
      Returns:
      The total number of threads currently in the pool
    • getIdleThreads

      @ManagedAttribute("number of idle threads in the pool") public int getIdleThreads()
      Specified by:
      getIdleThreads in interface ThreadPool
      Returns:
      The number of idle threads in the pool
    • execute

      public void execute(Runnable command)
      Specified by:
      execute in interface Executor
      Specified by:
      execute in interface TryExecutor
    • tryExecute

      public boolean tryExecute(Runnable task)
      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.
    • isLowOnThreads

      @ManagedAttribute(value="thread pool is low on threads", readonly=true) public boolean isLowOnThreads()
      Specified by:
      isLowOnThreads in interface ThreadPool
      Returns:
      True if the pool is low on threads
    • getVirtualThreadsExecutor

      public Executor getVirtualThreadsExecutor()
      Specified by:
      getVirtualThreadsExecutor in interface VirtualThreads.Configurable
      Returns:
      the Executor to use to execute tasks in virtual threads
    • setVirtualThreadsExecutor

      public void setVirtualThreadsExecutor(Executor executor)
      Specified by:
      setVirtualThreadsExecutor in interface VirtualThreads.Configurable
      Parameters:
      executor - the Executor to use to execute tasks in virtual threads
      See Also:
    • doStart

      protected void doStart() throws Exception
      Description copied from class: ContainerLifeCycle
      Starts the managed lifecycle beans in the order they were added.
      Overrides:
      doStart in class ContainerLifeCycle
      Throws:
      AbstractLifeCycle.StopException - If thrown, the lifecycle will immediately be stopped.
      Exception - If there was a problem starting. Will cause a transition to FAILED state
    • doStop

      protected void doStop() throws Exception
      Description copied from class: ContainerLifeCycle
      Stops the managed lifecycle beans in the reverse order they were added.
      Overrides:
      doStop in class ContainerLifeCycle
      Throws:
      Exception - If there was a problem stopping. Will cause a transition to FAILED state
    • join

      public void join() throws InterruptedException
      Description copied from interface: ThreadPool
      Blocks until the thread pool is stopped.
      Specified by:
      join in interface ThreadPool
      Throws:
      InterruptedException - if thread was interrupted
    • getThreadPoolBudget

      public ThreadPoolBudget getThreadPoolBudget()
      Specified by:
      getThreadPoolBudget in interface ThreadPool.SizedThreadPool
      Returns:
      a ThreadPoolBudget for this sized thread pool, or null of no ThreadPoolBudget can be returned
    • newThread

      protected Thread newThread(Runnable job)
    • dump

      public void dump(Appendable out, String indent) throws IOException
      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:
      IOException - if unable to write to Appendable
    • toString

      public String toString()
      Overrides:
      toString in class AbstractLifeCycle