diff --git a/README.md b/README.md index da371244..92ed22b4 100644 --- a/README.md +++ b/README.md @@ -242,21 +242,28 @@ Hippo-4J 通过对 JDK 线程池增强,以及扩展三方框架底层线程池 Serenity + + + baymax55 +
+ Baymax55 +
+ gewuwo
格悟沃
- + + hushtian
Null
- - + jinlingmei @@ -312,15 +319,15 @@ Hippo-4J 通过对 JDK 线程池增强,以及扩展三方框架底层线程池
Null
- + + onesimplecoder
Alic
- - + CalebZYC @@ -376,21 +383,14 @@ Hippo-4J 通过对 JDK 线程池增强,以及扩展三方框架底层线程池
WuLang
- + + alexhaoxuan
Alexli
- - - - - baymax55 -
- Baymax55 -
diff --git a/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/ThreadPoolBuilder.java b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/ThreadPoolBuilder.java index 1aa069c4..91ff100a 100644 --- a/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/ThreadPoolBuilder.java +++ b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/support/ThreadPoolBuilder.java @@ -17,14 +17,19 @@ package cn.hippo4j.core.executor.support; +import java.math.BigDecimal; +import java.util.Optional; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.RejectedExecutionHandler; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + import cn.hippo4j.common.design.builder.Builder; import cn.hippo4j.common.executor.support.BlockingQueueTypeEnum; import cn.hippo4j.common.toolkit.Assert; -import org.springframework.core.task.TaskDecorator; -import java.math.BigDecimal; -import java.util.Optional; -import java.util.concurrent.*; +import org.springframework.core.task.TaskDecorator; /** * Thread-pool builder. @@ -221,6 +226,19 @@ public class ThreadPoolBuilder implements Builder { return new ThreadPoolBuilder(); } + /** + * Create dynamic thread pool by thread pool id + * @param threadPoolId threadPoolId + * @return ThreadPoolExecutor + */ + public static ThreadPoolExecutor builderDynamicPoolById(String threadPoolId) { + return ThreadPoolBuilder.builder() + .threadFactory(threadPoolId) + .threadPoolId(threadPoolId) + .dynamicPool() + .build(); + } + private static ThreadPoolExecutor buildPool(ThreadPoolBuilder builder) { return AbstractBuildThreadPoolTemplate.buildPool(buildInitParam(builder)); } diff --git a/hippo4j-example/hippo4j-config-etcd-spring-boot-starter-example/src/main/java/cn/hippo4j/example/config/etcd/config/ThreadPoolConfig.java b/hippo4j-example/hippo4j-config-etcd-spring-boot-starter-example/src/main/java/cn/hippo4j/example/config/etcd/config/ThreadPoolConfig.java index 3f3e33cc..db3f1ad2 100644 --- a/hippo4j-example/hippo4j-config-etcd-spring-boot-starter-example/src/main/java/cn/hippo4j/example/config/etcd/config/ThreadPoolConfig.java +++ b/hippo4j-example/hippo4j-config-etcd-spring-boot-starter-example/src/main/java/cn/hippo4j/example/config/etcd/config/ThreadPoolConfig.java @@ -35,11 +35,6 @@ public class ThreadPoolConfig { @SpringDynamicThreadPool public ThreadPoolExecutor messageConsumeDynamicExecutor() { String threadPoolId = "message-consume"; - ThreadPoolExecutor messageConsumeDynamicExecutor = ThreadPoolBuilder.builder() - .threadFactory(threadPoolId) - .threadPoolId(threadPoolId) - .dynamicPool() - .build(); - return messageConsumeDynamicExecutor; + return ThreadPoolBuilder.builderDynamicPoolById(threadPoolId); } }