Class JPPFThreadPool2

java.lang.Object
java.util.concurrent.AbstractExecutorService
org.jppf.utils.concurrent.JPPFThreadPool2
All Implemented Interfaces:
Executor, ExecutorService

public class JPPFThreadPool2 extends AbstractExecutorService
A thread pool based on an ubounded queue which supports a core and maximum number of threads, along with a TTL for non-core threads.

Core threads are always live and are always prefered when available for new tasks. Non-core threads are created up to the maximum number of threads, after which tasks are simpy put into the queue.

Author:
Laurent Cohen
  • Constructor Details

    • JPPFThreadPool2

      public JPPFThreadPool2(int coreThreads)
      Create a fixed size thread pool with the specified number of threads, infinite thread time-to-live and a default thread factory.
      Parameters:
      coreThreads - the number of threads in the pool.
    • JPPFThreadPool2

      public JPPFThreadPool2(int coreThreads, ThreadFactory threadFactory)
      Initialize with the specified number of core threads and thread factory.
      Parameters:
      coreThreads - the number of core threads.
      threadFactory - the thread factory.
    • JPPFThreadPool2

      public JPPFThreadPool2(int coreThreads, int maxThreads, long ttl)
      Initialize with the specified number of core threads, maximum number of threads, thread ttl and a default thread factory.
      Parameters:
      coreThreads - the number of core threads.
      maxThreads - the maximum number of threads.
      ttl - the thread time-to-live in milliseconds.
    • JPPFThreadPool2

      public JPPFThreadPool2(int coreThreads, int maxThreads, long ttl, ThreadFactory threadFactory)
      Initialize with the specified number of core threads, maximum number of threads, ttl and thread factory.
      Parameters:
      coreThreads - the number of core threads.
      maxThreads - the maximum number of threads.
      ttl - the thread time-to-live in milliseconds.
      threadFactory - the thread factory.
    • JPPFThreadPool2

      public JPPFThreadPool2(int coreThreads, int maxThreads, long ttl, ThreadFactory threadFactory, BlockingQueue<Runnable> queue)
      Initialize with the specified number of core threads, maximum number of threads, ttl and thread factory.
      Parameters:
      coreThreads - the number of core threads.
      maxThreads - the maximum number of threads.
      ttl - the thread time-to-live in milliseconds.
      threadFactory - the thread factory.
      queue - the queue to use.
  • Method Details

    • getMaxThreads

      public int getMaxThreads()
      Returns:
      the maximum number of threads.
    • setMaxThreads

      public void setMaxThreads(int maxThreads)
      Set the maximum number of threads.
      Parameters:
      maxThreads - the new maximum number of threads.
    • getTtl

      public long getTtl()
      Returns:
      the non-threads' time-to-live.
    • setTtl

      public void setTtl(long ttl)
      Set the non-core threads' time-to-live.
      Parameters:
      ttl - the ttl in millis.
    • getPeakThreadCount

      public int getPeakThreadCount()
      Returns:
      the peak thread count for this thread pool.
    • execute

      public void execute(Runnable task)
      Execute the specified task some time in the future.
      Parameters:
      task - the task to execute.
    • shutdown

      public void shutdown()
    • shutdownNow

      public List<Runnable> shutdownNow()
    • isShutdown

      public boolean isShutdown()
    • isTerminated

      public boolean isTerminated()
    • awaitTermination

      public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException
      Throws:
      InterruptedException
    • toString

      public String toString()
      Overrides:
      toString in class Object