From d6bb0c378a73e1f25b2b11ec9347c35c085747f2 Mon Sep 17 00:00:00 2001 From: "chen.ma" Date: Wed, 7 Jul 2021 18:00:16 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E6=B1=A0=E5=88=9B=E5=BB=BA.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adapter/ThreadPoolConfigAdapter.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/adapter/ThreadPoolConfigAdapter.java b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/adapter/ThreadPoolConfigAdapter.java index 8e43f0be..16557df8 100644 --- a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/adapter/ThreadPoolConfigAdapter.java +++ b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/adapter/ThreadPoolConfigAdapter.java @@ -1,8 +1,9 @@ package io.dynamic.threadpool.starter.adapter; -import cn.hutool.core.thread.ThreadFactoryBuilder; import io.dynamic.threadpool.common.config.ApplicationContextHolder; +import io.dynamic.threadpool.common.enums.QueueTypeEnum; import io.dynamic.threadpool.starter.operation.ThreadPoolOperation; +import io.dynamic.threadpool.starter.toolkit.thread.ThreadPoolBuilder; import io.dynamic.threadpool.starter.wrap.DynamicThreadPoolWrap; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.annotation.Order; @@ -11,7 +12,6 @@ import javax.annotation.PostConstruct; import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ExecutorService; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; @@ -27,14 +27,13 @@ public class ThreadPoolConfigAdapter extends ConfigAdapter { @Autowired private ThreadPoolOperation threadPoolOperation; - private ExecutorService executorService = new ThreadPoolExecutor( - 2, - 4, - 0, - TimeUnit.MILLISECONDS, - new ArrayBlockingQueue(1), - new ThreadFactoryBuilder().setNamePrefix("threadPool-config").build(), - new ThreadPoolExecutor.DiscardOldestPolicy()); + private ExecutorService executorService = ThreadPoolBuilder.builder() + .poolThreadNum(2, 4) + .keepAliveTime(0L, TimeUnit.MILLISECONDS) + .workQueue(QueueTypeEnum.ARRAY_BLOCKING_QUEUE, 1) + .threadFactory("threadPool-config") + .rejected(new ThreadPoolExecutor.DiscardOldestPolicy()) + .build(); @Order(1025) @PostConstruct