diff --git a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/common/CommonThreadPool.java b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/common/CommonThreadPool.java index ab628d0b..d6cfa0fd 100644 --- a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/common/CommonThreadPool.java +++ b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/common/CommonThreadPool.java @@ -1,6 +1,11 @@ package io.dynamic.threadpool.starter.common; -import java.util.concurrent.*; +import io.dynamic.threadpool.common.enums.QueueTypeEnum; +import io.dynamic.threadpool.starter.builder.ThreadPoolBuilder; +import io.dynamic.threadpool.starter.toolkit.thread.RejectedPolicies; + +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; /** * 公共线程池生产者 @@ -11,20 +16,17 @@ import java.util.concurrent.*; public class CommonThreadPool { public static ThreadPoolExecutor getInstance(String threadPoolId) { - TimeUnit unit = TimeUnit.SECONDS; - BlockingQueue workQueue = new LinkedBlockingQueue(512); - ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor( - 3, - 5, - 10000, - unit, - workQueue, - r -> { - Thread thread = new Thread(r); - thread.setDaemon(false); - thread.setName(threadPoolId); - return thread; - }); + ThreadPoolExecutor poolExecutor = ThreadPoolBuilder.builder() + .threadFactory(threadPoolId) + .corePoolNum(3) + .maxPoolNum(5) + .capacity(512) + .keepAliveTime(10000L) + .timeUnit(TimeUnit.SECONDS) + .isFastPool(false) + .rejected(RejectedPolicies.runsOldestTaskPolicy()) + .workQueue(QueueTypeEnum.RESIZABLE_LINKED_BLOCKING_QUEUE) + .build(); return poolExecutor; } }