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);