diff --git a/snail-job-client/snail-job-client-job-core/src/main/java/com/aizuda/snailjob/client/job/core/cache/ThreadPoolCache.java b/snail-job-client/snail-job-client-job-core/src/main/java/com/aizuda/snailjob/client/job/core/cache/ThreadPoolCache.java index f4649120d..fb1c384e9 100644 --- a/snail-job-client/snail-job-client-job-core/src/main/java/com/aizuda/snailjob/client/job/core/cache/ThreadPoolCache.java +++ b/snail-job-client/snail-job-client-job-core/src/main/java/com/aizuda/snailjob/client/job/core/cache/ThreadPoolCache.java @@ -45,7 +45,11 @@ public class ThreadPoolCache { }; ThreadPoolExecutor threadPoolExecutor = supplier.get(); - CACHE_THREAD_POOL.putIfAbsent(taskBatchId, threadPoolExecutor); + ThreadPoolExecutor cacheThreadPoolExecutor = CACHE_THREAD_POOL.putIfAbsent(taskBatchId, threadPoolExecutor); + if (Objects.nonNull(cacheThreadPoolExecutor) && cacheThreadPoolExecutor != threadPoolExecutor) { + cacheThreadPoolExecutor.setCorePoolSize(Math.min(parallelNum, cacheThreadPoolExecutor.getMaximumPoolSize())); + return cacheThreadPoolExecutor; + } return threadPoolExecutor; }