Interface ThreadPool

All Superinterfaces:
Executor
All Known Subinterfaces:
ThreadPool.SizedThreadPool
All Known Implementing Classes:
DelegatingThreadPool, ExecutorThreadPool, MonitoredQueuedThreadPool, QueuedThreadPool, VirtualThreadPool

@ManagedObject("Pool of Threads") public interface ThreadPool extends Executor

A pool for threads.

A specialization of Executor interface that provides reporting methods (eg getThreads()) and the option of configuration methods (e.g. @link ThreadPool.SizedThreadPool.setMaxThreads(int)).

  • Method Details

    • join

      void join() throws InterruptedException
      Blocks until the thread pool is stopped.
      Throws:
      InterruptedException - if thread was interrupted
    • getThreads

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

      @ManagedAttribute("number of idle threads in pool") int getIdleThreads()
      Returns:
      The number of idle threads in the pool
    • isLowOnThreads

      @ManagedAttribute("indicates the pool is low on available threads") boolean isLowOnThreads()
      Returns:
      True if the pool is low on threads
    • executeImmediately

      static void executeImmediately(Executor executor, Runnable task)

      Execute a task immediately without queueing. This may use a ReservedThread, a Virtual Thread, a call to Invocable.invokeNonBlocking(Runnable), a newly spawned thread, or direct execution.

      Parameters:
      executor - An executor that may be used
      task - The task that must be executed.
    • reject

      static boolean reject(Runnable task, Throwable cause)
      Rejects a job that cannot be executed.
      Parameters:
      task - The job to be rejected
      cause - The reason for the rejection
      Returns:
      True if the job was closed, false if it was not a Closeable job.