线程池工具类
通过该工具类可以快速创建一个线程池,目前在 定时任务模块中使用到 ,代码地址:
eladmin-system -> me.zhengjie.config.ThreadPoolExecutorUtil
源码如下:
/**
* 用于获取自定义线程池
* @author Zheng Jie
* @date 2019年10月31日18:16:47
*/
public class ThreadPoolExecutorUtil {
public static ThreadPoolExecutor getPoll(){
AsyncTaskProperties properties = SpringContextHolder.getBean(AsyncTaskProperties.class);
return new ThreadPoolExecutor(
properties.getCorePoolSize(),
properties.getMaxPoolSize(),
properties.getKeepAliveSeconds(),
TimeUnit.SECONDS,
new ArrayBlockingQueue<>(properties.getQueueCapacity()),
new TheadFactoryName()
);
}
}
使用方式:
private final static ThreadPoolExecutor executor = ThreadPoolExecutorUtil.getPoll();