From e2d01931f7fc9e9035afaf5384708fc3f6ec9c03 Mon Sep 17 00:00:00 2001 From: "chen.ma" Date: Wed, 28 Jul 2021 21:06:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8A=A8=E6=80=81=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E6=B1=A0=E5=8A=9F=E8=83=BD=E9=80=BB=E8=BE=91=E5=AE=8C=E5=96=84?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../starter/toolkit/thread/CustomThreadPoolExecutor.java | 9 +++++++++ .../thread/ResizableCapacityLinkedBlockIngQueue.java | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/toolkit/thread/CustomThreadPoolExecutor.java b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/toolkit/thread/CustomThreadPoolExecutor.java index 62d3783d..3d195272 100644 --- a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/toolkit/thread/CustomThreadPoolExecutor.java +++ b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/toolkit/thread/CustomThreadPoolExecutor.java @@ -717,6 +717,15 @@ public final class CustomThreadPoolExecutor extends ThreadPoolExecutorTemplate { addWorker(null, true); } + void ensurePrestart() { + int wc = workerCountOf(ctl.get()); + if (wc < corePoolSize) { + addWorker(null, true); + } else if (wc == 0) { + addWorker(null, false); + } + } + @Override public int prestartAllCoreThreads() { int n = 0; diff --git a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/toolkit/thread/ResizableCapacityLinkedBlockIngQueue.java b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/toolkit/thread/ResizableCapacityLinkedBlockIngQueue.java index 8381f555..c8124c20 100644 --- a/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/toolkit/thread/ResizableCapacityLinkedBlockIngQueue.java +++ b/dynamic-threadpool-spring-boot-starter/src/main/java/io/dynamic/threadpool/starter/toolkit/thread/ResizableCapacityLinkedBlockIngQueue.java @@ -18,7 +18,7 @@ public class ResizableCapacityLinkedBlockIngQueue extends LinkedBlockingQueue super(capacity); } - public boolean setCapacity(Integer capacity) { + public synchronized boolean setCapacity(Integer capacity) { boolean successFlag = true; try { ReflectUtil.setFieldValue(this, "capacity", capacity);