Class ThreadPoolExecutorHandler

All Implemented Interfaces:
Executor, ExecutorService

public class ThreadPoolExecutorHandler extends ThreadPoolExecutor
重写线程池 打印当前的线程信息
  • Field Details

    • poolName

      private final String poolName
      线程池名称
    • KEEP_ALIVE_TIME

      private static final long KEEP_ALIVE_TIME
      线程池维护线程所允许的空闲时间
      See Also:
    • QUEUE_CAPACITY

      private static final int QUEUE_CAPACITY
      队列最大长度
      See Also:
    • log

      private static final org.slf4j.Logger log
  • Constructor Details

    • ThreadPoolExecutorHandler

      public ThreadPoolExecutorHandler(String poolName)
      初始化线程池 核心数默认为 cpu+1 对列数为 8192 拒绝策略为抛出异常
      Parameters:
      poolName - 线程名称
    • ThreadPoolExecutorHandler

      public ThreadPoolExecutorHandler(String poolName, RejectedExecutionHandler handler)
      初始化线程池 核心数默认为 cpu+1 对列数为 8192
      Parameters:
      poolName - 线程名称
      handler - 拒绝策略
    • ThreadPoolExecutorHandler

      public ThreadPoolExecutorHandler(int corePoolSize, int maximumPoolSize, long keepAliveTime, @NotNull @NotNull TimeUnit unit, @NotNull @NotNull BlockingQueue<Runnable> workQueue, String poolName, RejectedExecutionHandler handler)
      初始化线程池
      Parameters:
      corePoolSize - 核心数
      maximumPoolSize - 最大核心数
      keepAliveTime - 空闲时间
      unit - 空闲时间单位
      workQueue - 对列
      poolName - 线程名称
      handler - 拒绝策略
  • Method Details

    • beforeExecute

      protected void beforeExecute(Thread t, Runnable r)
      打印线程池运行状态
      Overrides:
      beforeExecute in class ThreadPoolExecutor
      Parameters:
      t - the thread that will run task r
      r - the task that will be executed