Class ThreadPool

java.lang.Object
io.github.connellite.concurrent.ThreadPool
All Implemented Interfaces:
AutoCloseable

public class ThreadPool extends Object implements AutoCloseable
  • Constructor Details

    • ThreadPool

      public ThreadPool(int threads)
      The constructor just launches some amount of workers
      Parameters:
      threads - number of threads
      Throws:
      IllegalStateException - if number of threads is less than or equal to 0
  • Method Details

    • enqueue

      public void enqueue(Runnable task)
      Add new work item to the pool
      Parameters:
      task - work item
      Throws:
      IllegalStateException - if stopped ThreadPool
    • enqueue

      public <T> Future<T> enqueue(Callable<T> task)
      Add new work item to the pool
      Type Parameters:
      T - The result type returned by this Future's get method
      Parameters:
      task - work item
      Returns:
      Future<T>
      Throws:
      IllegalStateException - if stopped ThreadPool
    • close

      public void close()
      Join all threads, stop ThreadPool
      Specified by:
      close in interface AutoCloseable