Class ExpandingThreadPoolExecutorFactory

java.lang.Object
com.illumon.util.ExpandingThreadPoolExecutorFactory

public class ExpandingThreadPoolExecutorFactory
extends Object
Creates a ThreadPoolExecutor which can then be used to submit or execute tasks. This is intended for cases where a relatively small number of threads can handle most circumstances, but occasional abnormal events may exceed expectations. The executor has the following characteristics:
  • Starting core and maximum thread pool sizes defined at creation time
  • If an attempted execution exceeds the maximum number of allowed executor threads, a new Thread will be created dynamically instead of generating an exception
If the executor has been shut down, any excess events will be discarded. To create one of these executors, use createThreadPoolExecutor(com.fishlib.io.logger.Logger, int, int, java.lang.String, java.lang.String, java.lang.String).
  • Method Details

    • createThreadPoolExecutor

      public static ThreadPoolExecutor createThreadPoolExecutor​(com.fishlib.io.logger.Logger log, int corePoolSize, int keepAliveMinutes, String executorName, String poolThreadNamePrefix, String dynamicThreadNamePrefix)
      Create a ThreadPoolExecutor with the characteristics defined in ExpandingThreadPoolExecutorFactory.
      Parameters:
      log - a Logger to log messages
      corePoolSize - the core pool size (the executor will use this value for the initial core and maximum pool sizes)
      keepAliveMinutes - the number of minutes to keep alive core threads
      executorName - the name of the executor, used when logging dynamic thread creation
      poolThreadNamePrefix - the prefix for thread pool threads
      dynamicThreadNamePrefix - the prefix for dynamic (overflow) threads created when the maximum number of pool threads is exceeded