All Implemented Interfaces:
Executor, ExecutorService

public class ThreadPool extends ThreadPoolExecutor
A ThreadPoolExecutor with an extensible growth policy and queue state accessors.
  • Method Details

    • asThreadPool

      public static Optional<ThreadPool> asThreadPool(ExecutorService executor)
      Returns the given executor as a ThreadPool if possible.
      Parameters:
      executor - The executor.
      Returns:
      The thread pool or empty if not a ThreadPool.
    • getName

      public String getName()
      Returns the name of this pool.
      Returns:
      The name.
    • getQueueCapacity

      public int getQueueCapacity()
      Returns the queue capacity.
      Returns:
      The capacity.
    • getAverageQueueSize

      public float getAverageQueueSize()
      Returns the average queue size.
      Returns:
      The size.
    • getPeakQueueSize

      public int getPeakQueueSize()
      Returns the peak queue size.
      Returns:
      The size.
    • getCompletedTasks

      public int getCompletedTasks()
      Returns the number of completed tasks.
      Returns:
      The count.
    • getFailedTasks

      public int getFailedTasks()
      Returns the number of tasks that threw an exception.
      Returns:
      The count.
    • getTotalTasks

      public int getTotalTasks()
      Returns the number of completed and failed tasks.
      Returns:
      The count.
    • getActiveThreads

      public int getActiveThreads()
      Returns the current number of active threads.
      Returns:
      The count.
    • getAverageActiveThreads

      public float getAverageActiveThreads()
      Returns the average number of active threads across the life of the pool.
      Returns:
      The average.
    • getRejectionCount

      public int getRejectionCount()
      Returns the rejection count.
      Returns:
      The count.
    • isFixedSize

      public boolean isFixedSize()
      Tests whether or not the number of threads can change over time.
      Returns:
      true if maximum size is equal to core size.
    • getQueue

      public io.helidon.common.configurable.ThreadPool.WorkQueue getQueue()
      Overrides:
      getQueue in class ThreadPoolExecutor
    • getQueueSize

      public int getQueueSize()
      Returns the current number of tasks in the queue.
      Returns:
      The count.
    • setRejectedExecutionHandler

      public void setRejectedExecutionHandler(RejectedExecutionHandler handler)
      Overrides:
      setRejectedExecutionHandler in class ThreadPoolExecutor
    • getRejectedExecutionHandler

      public ThreadPool.RejectionHandler getRejectedExecutionHandler()
      Overrides:
      getRejectedExecutionHandler in class ThreadPoolExecutor
    • setMaximumPoolSize

      public void setMaximumPoolSize(int maximumPoolSize)
      Overrides:
      setMaximumPoolSize in class ThreadPoolExecutor
    • toString

      public String toString()
      Overrides:
      toString in class ThreadPoolExecutor
    • beforeExecute

      protected void beforeExecute(Thread t, Runnable r)
      Overrides:
      beforeExecute in class ThreadPoolExecutor
    • afterExecute

      protected void afterExecute(Runnable r, Throwable t)
      Overrides:
      afterExecute in class ThreadPoolExecutor
    • shutdown

      public void shutdown()
      Specified by:
      shutdown in interface ExecutorService
      Overrides:
      shutdown in class ThreadPoolExecutor
    • shutdownNow

      public List<Runnable> shutdownNow()
      Specified by:
      shutdownNow in interface ExecutorService
      Overrides:
      shutdownNow in class ThreadPoolExecutor