(),
+ new DaemonThreadFactory("Pool-" + poolName, true),
+ new ThreadPoolExecutor.CallerRunsPolicy());
+ }
+
+ public static ExecutorService getOrInitExecutors(String poolName, int poolSize) {
+ return executors.computeIfAbsent(poolName, key -> init(poolName, poolSize));
+ }
+
+ public static void releaseExecutors(String poolName) {
+ ExecutorService executorService = executors.remove(poolName);
+ if (executorService != null) {
+ executorService.shutdown();
+ }
+ }
+}
diff --git a/milky-concurrent/milky-concurrent-future/src/main/java/cn/sliew/milky/concurrent/threadpool/DaemonThreadFactory.java b/milky-concurrent/milky-concurrent-future/src/main/java/cn/sliew/milky/concurrent/threadpool/DaemonThreadFactory.java
deleted file mode 100644
index 92cc669c..00000000
--- a/milky-concurrent/milky-concurrent-future/src/main/java/cn/sliew/milky/concurrent/threadpool/DaemonThreadFactory.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package cn.sliew.milky.concurrent.threadpool;
-
-import java.util.concurrent.ThreadFactory;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import static cn.sliew.milky.common.check.Ensures.checkNotNull;
-
-class DaemonThreadFactory implements ThreadFactory {
-
- private final int threadPriority = Thread.NORM_PRIORITY;
-
- private final String threadNamePrefix;
-
- private final boolean daemon;
-
- private final ThreadGroup threadGroup;
-
- private final AtomicInteger threadCount = new AtomicInteger(0);
-
- DaemonThreadFactory(String threadNamePrefix, boolean daemon, ThreadGroup threadGroup) {
- this.threadNamePrefix = checkNotNull(threadNamePrefix);
- this.daemon = daemon;
- SecurityManager s = System.getSecurityManager();
- this.threadGroup = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup();
- }
-
- @Override
- public Thread newThread(Runnable runnable) {
- Thread thread = new Thread(threadGroup, runnable, nextThreadName());
- thread.setPriority(threadPriority);
- thread.setDaemon(daemon);
- return thread;
- }
-
- /**
- * Return the thread name to use for a newly created {@link Thread}.
- * The default implementation returns the specified thread name prefix
- * with an increasing thread count appended: e.g. "SimpleAsyncTaskExecutor-0".
- */
- protected String nextThreadName() {
- return threadNamePrefix + this.threadCount.incrementAndGet();
- }
-}
diff --git a/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/MilkyThreadPoolExecutor.java b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/MilkyThreadPoolExecutor.java
index aeb1766a..b9814520 100644
--- a/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/MilkyThreadPoolExecutor.java
+++ b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/MilkyThreadPoolExecutor.java
@@ -1,6 +1,7 @@
package cn.sliew.milky.concurrent.thread;
import cn.sliew.milky.common.collect.ConcurrentReferenceHashMap;
+import cn.sliew.milky.common.concurrent.DaemonThreadFactory;
import cn.sliew.milky.common.concurrent.RunnableWrapper;
import cn.sliew.milky.common.exception.Rethrower;
import cn.sliew.milky.concurrent.thread.policy.AbortPolicyWithReport;
diff --git a/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/ThreadPoolExecutorBuilder.java b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/ThreadPoolExecutorBuilder.java
index 1f5cd7c1..d49988e6 100644
--- a/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/ThreadPoolExecutorBuilder.java
+++ b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/ThreadPoolExecutorBuilder.java
@@ -1,5 +1,6 @@
package cn.sliew.milky.concurrent.thread;
+import cn.sliew.milky.common.concurrent.DaemonThreadFactory;
import cn.sliew.milky.common.unit.TimeValue;
import cn.sliew.milky.common.unit.TimeValues;
import cn.sliew.milky.concurrent.thread.metrics.ThreadPoolExecutorMetrics;
diff --git a/pom.xml b/pom.xml
index 8dcf6492..f32b5433 100644
--- a/pom.xml
+++ b/pom.xml
@@ -79,18 +79,52 @@
${java.version}
true
3.0.0-M5
+
+ 1.18.32
+ 1.4.2.Final
+ 0.1.1
+ 0.2.0
+ 1.1.1
+ 2.17.1
+ 2.23.1
+ 4.0.0
+ 1.13.0
+ 5.8.30
+ 33.2.1-jre
org.apiguardian
apiguardian-api
- 1.1.1
+ ${apiguardian.version}
+
+ com.fasterxml.jackson
+ jackson-bom
+ ${jackson.version}
+ pom
+ import
+
+
+ org.apache.logging.log4j
+ log4j-bom
+ ${log4j.version}
+ pom
+ import
+
+
+ io.micrometer
+ micrometer-bom
+ ${micrometer.version}
+ pom
+ import
+
+
${project.groupId}
milky-common
@@ -117,33 +151,37 @@
${project.version}
-
- com.fasterxml.jackson
- jackson-bom
- 2.13.5
- pom
- import
+ org.projectlombok
+ lombok
+ ${lombok.version}
- org.apache.logging.log4j
- log4j-bom
- 2.17.1
- pom
- import
+ org.mapstruct
+ mapstruct
+ ${org.mapstruct.version}
- io.micrometer
- micrometer-bom
- 1.7.4
- pom
- import
+ org.mapstruct.extensions.spring
+ mapstruct-spring-annotations
+ ${org.mapstruct.extensions.spring.version}
+
+
+
+ cn.hutool
+ hutool-all
+ ${hutool.version}
+
+
+ com.google.guava
+ guava
+ ${guava.version}
com.lmax
disruptor
- 3.4.4
+ ${disruptor.version}
@@ -367,6 +405,23 @@
**/package-info.java
+
+
+ org.projectlombok
+ lombok
+ ${lombok.version}
+
+
+ org.mapstruct
+ mapstruct-processor
+ ${mapstruct.version}
+
+
+ org.projectlombok
+ lombok-mapstruct-binding
+ ${mapstruct.lombok.binding.version}
+
+