Pre Merge pull request !88 from 北极星/client-jdk8
This commit is contained in:
commit
35b8f2bb6a
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user