Supplier<ThreadPoolExecutor> supplier = () -> {
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
// 默认情况先只设置一个线程, 只有分片任务(静态分片、MAP、MapReduce)才会需要多线程支持
1, parallelNum, 10, TimeUnit.SECONDS, new LinkedBlockingQueue<>(10000),
new CustomizableThreadFactory(MessageFormat.format("snail-job-job-{0}-", taskBatchId)));
threadPoolExecutor.allowCoreThreadTimeOut(true);
return threadPoolExecutor;
};
ThreadPoolExecutor threadPoolExecutor = supplier.get();
如上图的ThreadPoolCache
类中获取线程池的方法,每一个taskBatchId都会创建一个线程池,如果我有大量的任务发送到客户端执行,那就是会启动很多的线程池,执行完毕后销毁。
大佬,请问下我的理解是否正确,如果这种场景是否需自行改造使用线程池复用的方式。谢谢