From 7c35e2817ae8d64a206a61b3a12c31d8b14d025e Mon Sep 17 00:00:00 2001 From: "chen.ma" Date: Tue, 6 Jul 2021 09:06:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8A=9F=E8=83=BD=E6=8C=81=E7=BB=AD?= =?UTF-8?q?=E6=9B=B4=E6=96=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../starter/common/CommonThreadPool.java | 12 ++++------ .../thread}/ThreadPoolBuilder.java | 22 +++++++++++++++++-- 2 files changed, 24 insertions(+), 10 deletions(-) rename dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/{builder => toolkit/thread}/ThreadPoolBuilder.java (88%) 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 d6cfa0fd..ca9ac330 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,7 +1,7 @@ package io.dynamic.threadpool.starter.common; import io.dynamic.threadpool.common.enums.QueueTypeEnum; -import io.dynamic.threadpool.starter.builder.ThreadPoolBuilder; +import io.dynamic.threadpool.starter.toolkit.thread.ThreadPoolBuilder; import io.dynamic.threadpool.starter.toolkit.thread.RejectedPolicies; import java.util.concurrent.ThreadPoolExecutor; @@ -18,14 +18,10 @@ public class CommonThreadPool { public static ThreadPoolExecutor getInstance(String threadPoolId) { ThreadPoolExecutor poolExecutor = ThreadPoolBuilder.builder() .threadFactory(threadPoolId) - .corePoolNum(3) - .maxPoolNum(5) - .capacity(512) - .keepAliveTime(10000L) - .timeUnit(TimeUnit.SECONDS) - .isFastPool(false) + .poolThreadNum(3, 5) + .keepAliveTime(1000L, TimeUnit.SECONDS) .rejected(RejectedPolicies.runsOldestTaskPolicy()) - .workQueue(QueueTypeEnum.RESIZABLE_LINKED_BLOCKING_QUEUE) + .workQueue(QueueTypeEnum.RESIZABLE_LINKED_BLOCKING_QUEUE, 512) .build(); return poolExecutor; } diff --git a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/builder/ThreadPoolBuilder.java b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/toolkit/thread/ThreadPoolBuilder.java similarity index 88% rename from dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/builder/ThreadPoolBuilder.java rename to dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/toolkit/thread/ThreadPoolBuilder.java index 9963b4f7..f1f7bf81 100644 --- a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/builder/ThreadPoolBuilder.java +++ b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/toolkit/thread/ThreadPoolBuilder.java @@ -1,10 +1,10 @@ -package io.dynamic.threadpool.starter.builder; +package io.dynamic.threadpool.starter.toolkit.thread; import io.dynamic.threadpool.common.enums.QueueTypeEnum; import io.dynamic.threadpool.common.toolkit.Assert; +import io.dynamic.threadpool.starter.builder.Builder; import io.dynamic.threadpool.starter.toolkit.BlockingQueueUtil; -import io.dynamic.threadpool.starter.toolkit.thread.AbstractBuildThreadPoolTemplate; import java.math.BigDecimal; import java.util.concurrent.*; @@ -108,6 +108,12 @@ public class ThreadPoolBuilder implements Builder { return this; } + public ThreadPoolBuilder poolThreadNum(Integer corePoolNum, Integer maxPoolNum) { + this.corePoolNum = corePoolNum; + this.maxPoolNum = maxPoolNum; + return this; + } + public ThreadPoolBuilder keepAliveTime(Long keepAliveTime) { this.keepAliveTime = keepAliveTime; return this; @@ -118,11 +124,23 @@ public class ThreadPoolBuilder implements Builder { return this; } + public ThreadPoolBuilder keepAliveTime(Long keepAliveTime, TimeUnit timeUnit) { + this.keepAliveTime = keepAliveTime; + this.timeUnit = timeUnit; + return this; + } + public ThreadPoolBuilder capacity(Integer capacity) { this.capacity = capacity; return this; } + public ThreadPoolBuilder workQueue(QueueTypeEnum queueType, Integer capacity) { + this.queueType = queueType; + this.capacity = capacity; + return this; + } + public ThreadPoolBuilder rejected(RejectedExecutionHandler rejectedExecutionHandler) { this.rejectedExecutionHandler = rejectedExecutionHandler; return this;