线程池工具类

通过该工具类可以快速创建一个线程池,目前在 定时任务模块中使用到 ,代码地址:

  1. eladmin-system -> me.zhengjie.config.ThreadPoolExecutorUtil

源码如下:

  1. /**
  2. * 用于获取自定义线程池
  3. * @author Zheng Jie
  4. * @date 2019年10月31日18:16:47
  5. */
  6. public class ThreadPoolExecutorUtil {
  7. public static ThreadPoolExecutor getPoll(){
  8. AsyncTaskProperties properties = SpringContextHolder.getBean(AsyncTaskProperties.class);
  9. return new ThreadPoolExecutor(
  10. properties.getCorePoolSize(),
  11. properties.getMaxPoolSize(),
  12. properties.getKeepAliveSeconds(),
  13. TimeUnit.SECONDS,
  14. new ArrayBlockingQueue<>(properties.getQueueCapacity()),
  15. new TheadFactoryName()
  16. );
  17. }
  18. }

使用方式:

  1. private final static ThreadPoolExecutor executor = ThreadPoolExecutorUtil.getPoll();