Pre Merge pull request !86 from 北极星/client-jdk8

This commit is contained in:
北极星 2024-09-06 13:25:40 +00:00 committed by Gitee
commit e5cd6c4a9a
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -24,13 +24,20 @@ public class ThreadPoolCache {
public static ThreadPoolExecutor createThreadPool(Long taskBatchId, int parallelNum) {
if (CACHE_THREAD_POOL.containsKey(taskBatchId)) {
return CACHE_THREAD_POOL.get(taskBatchId);
ThreadPoolExecutor threadPoolExecutor = CACHE_THREAD_POOL.get(taskBatchId);
if (threadPoolExecutor.getCorePoolSize() == parallelNum) {
return threadPoolExecutor;
} else {
threadPoolExecutor.setCorePoolSize(parallelNum);
threadPoolExecutor.setMaximumPoolSize(parallelNum);
}
return threadPoolExecutor;
}
Supplier<ThreadPoolExecutor> supplier = () -> {
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
parallelNum, parallelNum, 10, TimeUnit.SECONDS, new LinkedBlockingQueue<>(),
1, 1, 10, TimeUnit.SECONDS, new LinkedBlockingQueue<>(),
new CustomizableThreadFactory(MessageFormat.format("snail-job-job-{0}-", taskBatchId)));
threadPoolExecutor.allowCoreThreadTimeOut(true);
return threadPoolExecutor;