Class ExecutorServiceFactory

java.lang.Object
org.forgerock.util.thread.ExecutorServiceFactory

public class ExecutorServiceFactory extends Object
Responsible for generating ExecutorService instances which are automatically wired up to shutdown when the ShutdownListener event triggers. This factory simplifies the creation of ExecutorServices which could overlook the important step of registering with the ShutdownManager. Failure to do so will prevent the server from shutting down. Note: Executors created using this factory will be triggered with the ExecutorService#shutdownNow method. This will interrupt all blocking calls made by those threads. This may be important for some users.
Since:
1.3.5
  • Constructor Details

    • ExecutorServiceFactory

      public ExecutorServiceFactory(ShutdownManager shutdownManager)
      Create an instance of the factory.
      Parameters:
      shutdownManager - Required to ensure each ExecutorService will be shutdown.
  • Method Details

    • createScheduledService

      @Deprecated public ScheduledExecutorService createScheduledService(int poolSize)
      Deprecated.
      createScheduledService(int, String) should be used so that threads have meaningful names.
      Generates a ScheduledExecutorService which has been pre-registered with the ShutdownManager.
      Parameters:
      poolSize - The size of the ScheduledExecutorService thread pool.
      Returns:
      A non null ScheduledExecutorService
      See Also:
    • createScheduledService

      public ScheduledExecutorService createScheduledService(int poolSize, String threadNamePrefix)
      Generates a ScheduledExecutorService which has been pre-registered with the ShutdownManager.
      Parameters:
      poolSize - The size of the ScheduledExecutorService thread pool.
      threadNamePrefix - The thread name prefix to use when generating new threads.
      Returns:
      A non null ScheduledExecutorService
      See Also:
    • createCancellableScheduledService

      public ScheduledExecutorService createCancellableScheduledService(int poolSize, String threadNamePrefix)
      Generates a ScheduledExecutorService which has been pre-registered with the ShutdownManager and has the remove on cancel policy enabled.
      Parameters:
      poolSize - The size of the ScheduledExecutorService thread pool.
      threadNamePrefix - The thread name prefix to use when generating new threads.
      Returns:
      A non null ScheduledExecutorService
      See Also:
    • createFixedThreadPool

      public ExecutorService createFixedThreadPool(int pool, ThreadFactory factory)
      Creates a fixed size Thread Pool ExecutorService which has been pre-registered with the ShutdownManager.
      Parameters:
      pool - The size of the pool to create.
      factory - The ThreadFactory used to generate new threads.
      Returns:
      Non null.
    • createFixedThreadPool

      public ExecutorService createFixedThreadPool(int pool, String threadNamePrefix)
      Create a fixed size Thread Pool ExecutorService using the provided name as the prefix of the thread names.
      Parameters:
      pool - Size of the fixed pool.
      threadNamePrefix - The thread name prefix to use when generating new threads.
      Returns:
      Non null.
      See Also:
    • createFixedThreadPool

      @Deprecated public ExecutorService createFixedThreadPool(int pool)
      Deprecated.
      createFixedThreadPool(int, String) should be used so that threads have meaningful names.
      Create a fixed size Thread Pool ExecutorService.
      Parameters:
      pool - Size of the fixed pool.
      Returns:
      Non null.
      See Also:
    • createCachedThreadPool

      public ExecutorService createCachedThreadPool(ThreadFactory factory)
      Generates a Cached Thread Pool ExecutorService which has been pre-registered with the ShutdownManager. The provided ThreadFactory is used by the service when creating Threads.
      Parameters:
      factory - The ThreadFactory that will be used when generating threads. May not be null.
      Returns:
      A non null ExecutorService.
      See Also:
    • createCachedThreadPool

      public ExecutorService createCachedThreadPool(String threadNamePrefix)
      Generates a Cached Thread Pool ExecutorService using the provided name as a prefix of the thread names.
      Parameters:
      threadNamePrefix - The thread name prefix to use when generating new threads.
      Returns:
      Non null.
      See Also:
    • createCachedThreadPool

      @Deprecated public ExecutorService createCachedThreadPool()
      Deprecated.
      createCachedThreadPool(String) or createCachedThreadPool(ThreadFactory) should be used so that threads have meaningful names.
      Generates a Cached Thread Pool ExecutorService.
      Returns:
      Non null.
      See Also:
    • createThreadPool

      @Deprecated public ExecutorService createThreadPool(int coreSize, int maxSize, long idleTimeout, TimeUnit timeoutTimeunit, BlockingQueue<Runnable> runnables)
      Deprecated.
      createThreadPool(int, int, long, TimeUnit, BlockingQueue, String) should be used so that threads have meaningful names.
      Generates a ThreadPoolExecutor with the provided values, and registers that executor as listening for shutdown messages.
      Parameters:
      coreSize - the number of threads to keep in the pool, even if they are idle
      maxSize - Max number of threads in the pool
      idleTimeout - When the number of threads is greater than core, maximum time that excess idle threads will wait before terminating
      timeoutTimeunit - The time unit for the idleTimeout argument
      runnables - Queue of threads to be run
      Returns:
      a configured ExecutorService, registered to listen to shutdown messages.
    • createThreadPool

      public ExecutorService createThreadPool(int coreSize, int maxSize, long idleTimeout, TimeUnit timeoutTimeunit, BlockingQueue<Runnable> runnables, String threadNamePrefix)
      Generates a ThreadPoolExecutor with the provided values, and registers that executor as listening for shutdown messages.
      Parameters:
      coreSize - the number of threads to keep in the pool, even if they are idle
      maxSize - Max number of threads in the pool
      idleTimeout - When the number of threads is greater than core, maximum time that excess idle threads will wait before terminating
      timeoutTimeunit - The time unit for the idleTimeout argument
      runnables - Queue of threads to be run
      threadNamePrefix - The thread name prefix to use when generating new threads.
      Returns:
      a configured ExecutorService, registered to listen to shutdown messages.