diff --git a/milky-common/pom.xml b/milky-common/pom.xml index ef60de0e..7010825c 100644 --- a/milky-common/pom.xml +++ b/milky-common/pom.xml @@ -27,6 +27,11 @@ disruptor + + com.google.guava + guava + + com.fasterxml.jackson.core jackson-databind @@ -44,12 +49,6 @@ jackson-dataformat-properties - - com.google.guava - guava - 30.1.1-jre - test - cn.sliew milky-test diff --git a/milky-common/src/main/java/cn/sliew/milky/common/concurrent/AbstractLoopRunnable.java b/milky-common/src/main/java/cn/sliew/milky/common/concurrent/AbstractLoopRunnable.java new file mode 100644 index 00000000..867f4363 --- /dev/null +++ b/milky-common/src/main/java/cn/sliew/milky/common/concurrent/AbstractLoopRunnable.java @@ -0,0 +1,16 @@ +package cn.sliew.milky.common.concurrent; + +public abstract class AbstractLoopRunnable implements LoopRunnable { + + protected volatile boolean terminal = false; + + @Override + public void terminate() { + terminal = true; + } + + @Override + public boolean isTerminated() { + return terminal; + } +} diff --git a/milky-thread/src/main/java/cn/sliew/milky/thread/DaemonThreadFactory.java b/milky-common/src/main/java/cn/sliew/milky/common/concurrent/DaemonThreadFactory.java similarity index 86% rename from milky-thread/src/main/java/cn/sliew/milky/thread/DaemonThreadFactory.java rename to milky-common/src/main/java/cn/sliew/milky/common/concurrent/DaemonThreadFactory.java index 9dfbd054..50192cdf 100644 --- a/milky-thread/src/main/java/cn/sliew/milky/thread/DaemonThreadFactory.java +++ b/milky-common/src/main/java/cn/sliew/milky/common/concurrent/DaemonThreadFactory.java @@ -1,15 +1,11 @@ -package cn.sliew.milky.thread; +package cn.sliew.milky.common.concurrent; import java.util.concurrent.ThreadFactory; import java.util.concurrent.atomic.AtomicInteger; import static cn.sliew.milky.common.check.Ensures.checkNotNull; -import static cn.sliew.milky.common.check.Ensures.notBlank; -/** - * todo thread context。当创建线程的时候初始化线程的ThreadContext?? - */ -class DaemonThreadFactory implements ThreadFactory { +public class DaemonThreadFactory implements ThreadFactory { private final String threadNamePrefix; private final int threadPriority; @@ -23,7 +19,7 @@ public DaemonThreadFactory() { this(null); } - DaemonThreadFactory(String threadNamePrefix) { + public DaemonThreadFactory(String threadNamePrefix) { this(threadNamePrefix, true); } @@ -31,7 +27,7 @@ public DaemonThreadFactory(String threadNamePrefix, int threadPriority) { this(threadNamePrefix, threadPriority, true); } - DaemonThreadFactory(String threadNamePrefix, boolean daemon) { + public DaemonThreadFactory(String threadNamePrefix, boolean daemon) { this(threadNamePrefix, Thread.NORM_PRIORITY, daemon); } diff --git a/milky-common/src/main/java/cn/sliew/milky/common/concurrent/LoopRunnable.java b/milky-common/src/main/java/cn/sliew/milky/common/concurrent/LoopRunnable.java new file mode 100644 index 00000000..e6439b95 --- /dev/null +++ b/milky-common/src/main/java/cn/sliew/milky/common/concurrent/LoopRunnable.java @@ -0,0 +1,17 @@ +package cn.sliew.milky.common.concurrent; + +public interface LoopRunnable extends Runnable { + + void execute(); + + void terminate(); + + boolean isTerminated(); + + @Override + default void run() { + while (isTerminated() == false) { + execute(); + } + } +} diff --git a/milky-common/src/main/java/cn/sliew/milky/common/concurrent/RunnableWrapper.java b/milky-common/src/main/java/cn/sliew/milky/common/concurrent/RunnableWrapper.java index 54affa9e..c1cb9659 100644 --- a/milky-common/src/main/java/cn/sliew/milky/common/concurrent/RunnableWrapper.java +++ b/milky-common/src/main/java/cn/sliew/milky/common/concurrent/RunnableWrapper.java @@ -1,5 +1,7 @@ package cn.sliew.milky.common.concurrent; +import java.util.concurrent.RejectedExecutionException; + public interface RunnableWrapper extends Runnable { @Override @@ -8,7 +10,9 @@ default void run() { onBefore(); doRun(); onAfter(); - } catch (Exception t) { + } catch (RejectedExecutionException t) { + onRejection(t); + } catch (Exception t) { onFailure(t); } finally { onFinal(); @@ -27,6 +31,14 @@ default void run() { */ void onFailure(Exception e); + /** + * This should be executed if the thread-pool executing this action rejected the execution. + * The default implementation forwards to {@link #onFailure(Exception)} + */ + default void onRejection(Exception e) { + onFailure(e); + } + /** * This method is called before all execution for init. */ @@ -48,4 +60,11 @@ default void onAfter() throws Exception { default void onFinal() { // nothing by default } + + /** + * Should the runnable force its execution in case it gets rejected? + */ + default boolean isForceExecution() { + return false; + } } diff --git a/milky-common/src/main/java/cn/sliew/milky/common/concurrent/ThreadPoolUtil.java b/milky-common/src/main/java/cn/sliew/milky/common/concurrent/ThreadPoolUtil.java new file mode 100644 index 00000000..e0647038 --- /dev/null +++ b/milky-common/src/main/java/cn/sliew/milky/common/concurrent/ThreadPoolUtil.java @@ -0,0 +1,28 @@ +package cn.sliew.milky.common.concurrent; + +import java.util.concurrent.*; + +public enum ThreadPoolUtil { + ; + + private static ConcurrentMap executors = new ConcurrentHashMap<>(); + + private static ExecutorService init(String poolName, int poolSize) { + return new ThreadPoolExecutor(poolSize, poolSize, + 0L, TimeUnit.MILLISECONDS, + new LinkedBlockingQueue(), + 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-common/src/main/java/cn/sliew/milky/common/unit/MoneyUnit.java b/milky-common/src/main/java/cn/sliew/milky/common/unit/MoneyUnit.java new file mode 100644 index 00000000..454cf50e --- /dev/null +++ b/milky-common/src/main/java/cn/sliew/milky/common/unit/MoneyUnit.java @@ -0,0 +1,132 @@ +package cn.sliew.milky.common.unit; + +import java.math.BigDecimal; + +public enum MoneyUnit { + + HAO { + @Override + public BigDecimal toHao(BigDecimal size) { + return size; + } + + @Override + public BigDecimal toFen(BigDecimal size) { + return size.divide(C1.divide(C0)); + } + + @Override + public BigDecimal toJiao(BigDecimal size) { + return size.divide(C2.divide(C0)); + } + + @Override + public BigDecimal toYuan(BigDecimal size) { + return size.divide(C3.divide(C0)); + } + + @Override + public String getSuffix() { + return "毫"; + } + }, + + FEN { + + @Override + public BigDecimal toHao(BigDecimal size) { + return size.multiply(C1.divide(C0)); + } + + @Override + public BigDecimal toFen(BigDecimal size) { + return size; + } + + @Override + public BigDecimal toJiao(BigDecimal size) { + return size.divide(C2.divide(C1)); + } + + @Override + public BigDecimal toYuan(BigDecimal size) { + return size.divide(C3.divide(C1)); + } + + @Override + public String getSuffix() { + return "分"; + } + }, + + JIAO { + @Override + public BigDecimal toHao(BigDecimal size) { + return size.multiply(C2.divide(C0)); + } + + @Override + public BigDecimal toFen(BigDecimal size) { + return size.multiply(C2.divide(C1)); + } + + @Override + public BigDecimal toJiao(BigDecimal size) { + return size; + } + + @Override + public BigDecimal toYuan(BigDecimal size) { + return size.divide(C3.divide(C2)); + } + + @Override + public String getSuffix() { + return "角"; + } + }, + + YUAN { + @Override + public BigDecimal toHao(BigDecimal size) { + return size.multiply(C3.divide(C0)); + } + + @Override + public BigDecimal toFen(BigDecimal size) { + return size.multiply(C3.divide(C1)); + } + + @Override + public BigDecimal toJiao(BigDecimal size) { + return size.multiply(C3.divide(C2)); + } + + @Override + public BigDecimal toYuan(BigDecimal size) { + return size; + } + + @Override + public String getSuffix() { + return "元"; + } + }; + + static final BigDecimal _TEN = BigDecimal.TEN; + static final BigDecimal _HUNDRED = BigDecimal.valueOf(100L); + static final BigDecimal C0 = BigDecimal.ONE; + static final BigDecimal C1 = C0.multiply(_HUNDRED); + static final BigDecimal C2 = C1.multiply(_TEN); + static final BigDecimal C3 = C2.multiply(_TEN); + + public abstract BigDecimal toHao(BigDecimal size); + + public abstract BigDecimal toFen(BigDecimal size); + + public abstract BigDecimal toJiao(BigDecimal size); + + public abstract BigDecimal toYuan(BigDecimal size); + + public abstract String getSuffix(); +} diff --git a/milky-common/src/main/java/cn/sliew/milky/common/unit/MoneyValue.java b/milky-common/src/main/java/cn/sliew/milky/common/unit/MoneyValue.java new file mode 100644 index 00000000..58aea6f1 --- /dev/null +++ b/milky-common/src/main/java/cn/sliew/milky/common/unit/MoneyValue.java @@ -0,0 +1,128 @@ +package cn.sliew.milky.common.unit; + +import cn.sliew.milky.common.primitives.Strings; + +import java.math.BigDecimal; +import java.util.Locale; + +public class MoneyValue implements Comparable { + + public static final MoneyValue ZERO = new MoneyValue(BigDecimal.ZERO, MoneyUnit.HAO); + + private final BigDecimal value; + private final MoneyUnit unit; + + public MoneyValue(BigDecimal hao) { + this(hao, MoneyUnit.HAO); + } + + public MoneyValue(BigDecimal value, MoneyUnit unit) { + this.value = value; + this.unit = unit; + } + + public BigDecimal getHao() { + return unit.toHao(value); + } + + public BigDecimal getFen() { + return unit.toFen(value); + } + + public BigDecimal getJiao() { + return unit.toJiao(value); + } + + public BigDecimal getYuan() { + return unit.toYuan(value); + } + + public BigDecimal getFenFrac() { + return getHao().divide(MoneyUnit.C1); + } + + public BigDecimal getJiaoFrac() { + return getHao().divide(MoneyUnit.C2); + } + + public BigDecimal getYuanFrac() { + return getHao().divide(MoneyUnit.C3); + } + + public static MoneyValue parseMoneyValue(String value) throws ValueParseException { + return parseMoneyValue(value, null); + } + + public static MoneyValue parseMoneyValue(String value, MoneyValue defaultValue) throws ValueParseException { + if (value == null) { + return defaultValue; + } + String lowerValue = value.toLowerCase(Locale.ROOT).trim(); + if (lowerValue.endsWith("毫")) { + return parse(value, lowerValue, "毫", MoneyUnit.HAO); + } else if (lowerValue.endsWith("分")) { + return parse(value, lowerValue, "分", MoneyUnit.FEN); + } else if (lowerValue.endsWith("角")) { + return parse(value, lowerValue, "角", MoneyUnit.JIAO); + } else if (lowerValue.endsWith("元")) { + return parse(value, lowerValue, "元", MoneyUnit.YUAN); + } else if (lowerValue.equals("0")) { + // Allow this special value to be unit-less: + return new MoneyValue(BigDecimal.ZERO, MoneyUnit.HAO); + } else { + // Missing units: + throw new ValueParseException(String.format("failed to parse value [{}] as money: unit is missing or unrecognized", value)); + } + } + + private static MoneyValue parse(final String initialInput, final String normalized, final String suffix, MoneyUnit unit) { + final String s = normalized.substring(0, normalized.length() - suffix.length()).trim(); + try { + return new MoneyValue(BigDecimal.valueOf(Long.parseLong(s)), unit); + } catch (NumberFormatException e) { + throw new ValueParseException(String.format("failed to parse value [{}] as money", initialInput), e); + } + } + + @Override + public int compareTo(MoneyValue other) { + BigDecimal thisValue = value.multiply(unit.toHao(BigDecimal.ONE)); + BigDecimal otherValue = other.value.multiply(other.unit.toHao(BigDecimal.ONE)); + return thisValue.compareTo(otherValue); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + return compareTo((MoneyValue) o) == 0; + } + + @Override + public int hashCode() { + return value.multiply(unit.toHao(BigDecimal.ONE)).hashCode(); + } + + @Override + public String toString() { + BigDecimal hao = getHao(); + BigDecimal value = hao; + String suffix = MoneyUnit.HAO.getSuffix(); + if (value.compareTo(MoneyUnit.C3) >= 0) { + value = getYuanFrac(); + suffix = MoneyUnit.YUAN.getSuffix(); + } else if (value.compareTo(MoneyUnit.C2) >= 0) { + value = getJiaoFrac(); + suffix = MoneyUnit.JIAO.getSuffix(); + } else if (value.compareTo(MoneyUnit.C1) >= 0) { + value = getFenFrac(); + suffix = MoneyUnit.FEN.getSuffix(); + } + return Strings.format1Decimals(value.doubleValue(), suffix); + } +} diff --git a/milky-common/src/main/java/cn/sliew/milky/common/unit/NumberUnit.java b/milky-common/src/main/java/cn/sliew/milky/common/unit/NumberUnit.java new file mode 100644 index 00000000..4f74d92b --- /dev/null +++ b/milky-common/src/main/java/cn/sliew/milky/common/unit/NumberUnit.java @@ -0,0 +1,245 @@ +package cn.sliew.milky.common.unit; + +import java.math.BigDecimal; + +public enum NumberUnit { + + ONE { + @Override + public BigDecimal toOne(BigDecimal size) { + return size; + } + + @Override + public BigDecimal toTen(BigDecimal size) { + return size.divide(C1.divide(C0)); + } + + @Override + public BigDecimal toHundred(BigDecimal size) { + return size.divide(C2.divide(C0)); + } + + @Override + public BigDecimal toThousand(BigDecimal size) { + return size.divide(C3.divide(C0)); + } + + @Override + public BigDecimal toTenThousand(BigDecimal size) { + return size.divide(C4.divide(C0)); + } + + @Override + public BigDecimal toTenMillion(BigDecimal size) { + return size.divide(C5.divide(C0)); + } + + @Override + public String getSuffix() { + return ""; + } + }, + TEN { + @Override + public BigDecimal toOne(BigDecimal size) { + return size.multiply(C1.divide(C0)); + } + + @Override + public BigDecimal toTen(BigDecimal size) { + return size; + } + + @Override + public BigDecimal toHundred(BigDecimal size) { + return size.divide(C2.divide(C1)); + } + + @Override + public BigDecimal toThousand(BigDecimal size) { + return size.divide(C3.divide(C1)); + } + + @Override + public BigDecimal toTenThousand(BigDecimal size) { + return size.divide(C4.divide(C1)); + } + + @Override + public BigDecimal toTenMillion(BigDecimal size) { + return size.divide(C5.divide(C1)); + } + + @Override + public String getSuffix() { + return "十"; + } + }, + HUNDRED { + @Override + public BigDecimal toOne(BigDecimal size) { + return size.multiply(C2.divide(C0)); + } + + @Override + public BigDecimal toTen(BigDecimal size) { + return size.multiply(C2.divide(C1)); + } + + @Override + public BigDecimal toHundred(BigDecimal size) { + return size; + } + + @Override + public BigDecimal toThousand(BigDecimal size) { + return size.divide(C3.divide(C2)); + } + + @Override + public BigDecimal toTenThousand(BigDecimal size) { + return size.divide(C4.divide(C2)); + } + + @Override + public BigDecimal toTenMillion(BigDecimal size) { + return size.divide(C5.divide(C2)); + } + + @Override + public String getSuffix() { + return "百"; + } + }, + THOUSAND { + @Override + public BigDecimal toOne(BigDecimal size) { + return size.multiply(C3.divide(C0)); + } + + @Override + public BigDecimal toTen(BigDecimal size) { + return size.multiply(C3.divide(C1)); + } + + @Override + public BigDecimal toHundred(BigDecimal size) { + return size.multiply(C3.divide(C2)); + } + + @Override + public BigDecimal toThousand(BigDecimal size) { + return size; + } + + @Override + public BigDecimal toTenThousand(BigDecimal size) { + return size.divide(C4.divide(C3)); + } + + @Override + public BigDecimal toTenMillion(BigDecimal size) { + return size.divide(C5.divide(C3)); + } + + @Override + public String getSuffix() { + return "千"; + } + }, + TEN_THOUSAND { + @Override + public BigDecimal toOne(BigDecimal size) { + return size.multiply(C4.divide(C0)); + } + + @Override + public BigDecimal toTen(BigDecimal size) { + return size.multiply(C4.divide(C1)); + } + + @Override + public BigDecimal toHundred(BigDecimal size) { + return size.multiply(C4.divide(C2)); + } + + @Override + public BigDecimal toThousand(BigDecimal size) { + return size.multiply(C4.divide(C3)); + } + + @Override + public BigDecimal toTenThousand(BigDecimal size) { + return size; + } + + @Override + public BigDecimal toTenMillion(BigDecimal size) { + return size.divide(C5.divide(C4)); + } + + @Override + public String getSuffix() { + return "万"; + } + }, + TEN_MILLION { + @Override + public BigDecimal toOne(BigDecimal size) { + return size.multiply(C5.divide(C0)); + } + + @Override + public BigDecimal toTen(BigDecimal size) { + return size.multiply(C5.divide(C1)); + } + + @Override + public BigDecimal toHundred(BigDecimal size) { + return size.multiply(C5.divide(C2)); + } + + @Override + public BigDecimal toThousand(BigDecimal size) { + return size.multiply(C5.divide(C3)); + } + + @Override + public BigDecimal toTenThousand(BigDecimal size) { + return size.multiply(C5.divide(C4)); + } + + @Override + public BigDecimal toTenMillion(BigDecimal size) { + return size; + } + + @Override + public String getSuffix() { + return "亿"; + } + }; + + static final BigDecimal _TEN = BigDecimal.valueOf(10); + static final BigDecimal C0 = BigDecimal.ONE; + static final BigDecimal C1 = C0.multiply(_TEN); + static final BigDecimal C2 = C1.multiply(_TEN); + static final BigDecimal C3 = C2.multiply(_TEN); + static final BigDecimal C4 = C3.multiply(_TEN); + static final BigDecimal C5 = C4.multiply(BigDecimal.valueOf(10000L)); + + public abstract BigDecimal toOne(BigDecimal size); + + public abstract BigDecimal toTen(BigDecimal size); + + public abstract BigDecimal toHundred(BigDecimal size); + + public abstract BigDecimal toThousand(BigDecimal size); + + public abstract BigDecimal toTenThousand(BigDecimal size); + + public abstract BigDecimal toTenMillion(BigDecimal size); + + public abstract String getSuffix(); +} diff --git a/milky-common/src/test/java/cn/sliew/milky/common/unit/MoneyUnitTestCase.java b/milky-common/src/test/java/cn/sliew/milky/common/unit/MoneyUnitTestCase.java new file mode 100644 index 00000000..8d81a5b8 --- /dev/null +++ b/milky-common/src/test/java/cn/sliew/milky/common/unit/MoneyUnitTestCase.java @@ -0,0 +1,58 @@ +package cn.sliew.milky.common.unit; + +import cn.sliew.milky.test.MilkyTestCase; +import org.junit.jupiter.api.Test; + +import java.math.BigDecimal; + +import static cn.sliew.milky.common.unit.ByteUnit.*; +import static cn.sliew.milky.common.unit.MoneyUnit.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.equalTo; +import static org.junit.jupiter.api.Assertions.fail; + +public class MoneyUnitTestCase extends MilkyTestCase { + + @Test + void testHao() { + assertThat(HAO.toHao(BigDecimal.valueOf(1)), equalTo(BigDecimal.ONE)); + assertThat(HAO.toFen(BigDecimal.valueOf(100)), equalTo(BigDecimal.ONE)); + assertThat(HAO.toJiao(BigDecimal.valueOf(1000)), equalTo(BigDecimal.ONE)); + assertThat(HAO.toYuan(BigDecimal.valueOf(10000)), equalTo(BigDecimal.ONE)); + } + + @Test + void testFen() { + assertThat(FEN.toHao(BigDecimal.ONE), equalTo(BigDecimal.valueOf(100L))); + assertThat(FEN.toFen(BigDecimal.ONE), equalTo(BigDecimal.ONE)); + assertThat(FEN.toJiao(BigDecimal.TEN), equalTo(BigDecimal.ONE)); + assertThat(FEN.toYuan(BigDecimal.valueOf(100)), equalTo(BigDecimal.ONE)); + } + + @Test + void testJiao() { + assertThat(JIAO.toHao(BigDecimal.ONE), equalTo(BigDecimal.valueOf(1000))); + assertThat(JIAO.toFen(BigDecimal.ONE), equalTo(BigDecimal.TEN)); + assertThat(JIAO.toJiao(BigDecimal.ONE), equalTo(BigDecimal.ONE)); + assertThat(JIAO.toYuan(BigDecimal.TEN), equalTo(BigDecimal.ONE)); + } + + @Test + void testYuan() { + assertThat(YUAN.toHao(BigDecimal.ONE), equalTo(BigDecimal.valueOf(10000))); + assertThat(YUAN.toFen(BigDecimal.ONE), equalTo(BigDecimal.valueOf(100))); + assertThat(YUAN.toJiao(BigDecimal.ONE), equalTo(BigDecimal.valueOf(10))); + assertThat(YUAN.toYuan(BigDecimal.ONE), equalTo(BigDecimal.ONE)); + } + + @Test + void testToString() { + int v = randomIntBetween(1, 9); + assertThat(new MoneyValue(YUAN.toHao(BigDecimal.valueOf(v))).toString(), equalTo(v + "元")); + assertThat(new MoneyValue(JIAO.toHao(BigDecimal.valueOf(v))).toString(), equalTo(v + "角")); + assertThat(new MoneyValue(FEN.toHao(BigDecimal.valueOf(v))).toString(), equalTo(v + "分")); + assertThat(new MoneyValue(HAO.toHao(BigDecimal.valueOf(v))).toString(), equalTo(v + "毫")); + } + +} diff --git a/milky-concurrent/milky-concurrent-future/pom.xml b/milky-concurrent/milky-concurrent-future/pom.xml new file mode 100644 index 00000000..71f5a89c --- /dev/null +++ b/milky-concurrent/milky-concurrent-future/pom.xml @@ -0,0 +1,29 @@ + + + 4.0.0 + + cn.sliew + milky-concurrent + 1.0.14-SNAPSHOT + ../pom.xml + + milky-concurrent-future + + + true + + + + + cn.sliew + milky-common + + + cn.sliew + milky-test + test + + + \ No newline at end of file diff --git a/milky-concurrent/src/main/java/cn/sliew/milky/concurrent/AbstractFuture.java b/milky-concurrent/milky-concurrent-future/src/main/java/cn/sliew/milky/concurrent/AbstractFuture.java similarity index 100% rename from milky-concurrent/src/main/java/cn/sliew/milky/concurrent/AbstractFuture.java rename to milky-concurrent/milky-concurrent-future/src/main/java/cn/sliew/milky/concurrent/AbstractFuture.java diff --git a/milky-concurrent/src/main/java/cn/sliew/milky/concurrent/CompletableContext.java b/milky-concurrent/milky-concurrent-future/src/main/java/cn/sliew/milky/concurrent/CompletableContext.java similarity index 100% rename from milky-concurrent/src/main/java/cn/sliew/milky/concurrent/CompletableContext.java rename to milky-concurrent/milky-concurrent-future/src/main/java/cn/sliew/milky/concurrent/CompletableContext.java diff --git a/milky-concurrent/src/main/java/cn/sliew/milky/concurrent/CompleteFuture.java b/milky-concurrent/milky-concurrent-future/src/main/java/cn/sliew/milky/concurrent/CompleteFuture.java similarity index 100% rename from milky-concurrent/src/main/java/cn/sliew/milky/concurrent/CompleteFuture.java rename to milky-concurrent/milky-concurrent-future/src/main/java/cn/sliew/milky/concurrent/CompleteFuture.java diff --git a/milky-concurrent/src/main/java/cn/sliew/milky/concurrent/DefaultProgressivePromise.java b/milky-concurrent/milky-concurrent-future/src/main/java/cn/sliew/milky/concurrent/DefaultProgressivePromise.java similarity index 100% rename from milky-concurrent/src/main/java/cn/sliew/milky/concurrent/DefaultProgressivePromise.java rename to milky-concurrent/milky-concurrent-future/src/main/java/cn/sliew/milky/concurrent/DefaultProgressivePromise.java diff --git a/milky-concurrent/src/main/java/cn/sliew/milky/concurrent/DefaultPromise.java b/milky-concurrent/milky-concurrent-future/src/main/java/cn/sliew/milky/concurrent/DefaultPromise.java similarity index 100% rename from milky-concurrent/src/main/java/cn/sliew/milky/concurrent/DefaultPromise.java rename to milky-concurrent/milky-concurrent-future/src/main/java/cn/sliew/milky/concurrent/DefaultPromise.java diff --git a/milky-concurrent/src/main/java/cn/sliew/milky/concurrent/FailedFuture.java b/milky-concurrent/milky-concurrent-future/src/main/java/cn/sliew/milky/concurrent/FailedFuture.java similarity index 100% rename from milky-concurrent/src/main/java/cn/sliew/milky/concurrent/FailedFuture.java rename to milky-concurrent/milky-concurrent-future/src/main/java/cn/sliew/milky/concurrent/FailedFuture.java diff --git a/milky-concurrent/src/main/java/cn/sliew/milky/concurrent/Future.java b/milky-concurrent/milky-concurrent-future/src/main/java/cn/sliew/milky/concurrent/Future.java similarity index 100% rename from milky-concurrent/src/main/java/cn/sliew/milky/concurrent/Future.java rename to milky-concurrent/milky-concurrent-future/src/main/java/cn/sliew/milky/concurrent/Future.java diff --git a/milky-concurrent/src/main/java/cn/sliew/milky/concurrent/FutureListener.java b/milky-concurrent/milky-concurrent-future/src/main/java/cn/sliew/milky/concurrent/FutureListener.java similarity index 100% rename from milky-concurrent/src/main/java/cn/sliew/milky/concurrent/FutureListener.java rename to milky-concurrent/milky-concurrent-future/src/main/java/cn/sliew/milky/concurrent/FutureListener.java diff --git a/milky-concurrent/src/main/java/cn/sliew/milky/concurrent/Futures.java b/milky-concurrent/milky-concurrent-future/src/main/java/cn/sliew/milky/concurrent/Futures.java similarity index 100% rename from milky-concurrent/src/main/java/cn/sliew/milky/concurrent/Futures.java rename to milky-concurrent/milky-concurrent-future/src/main/java/cn/sliew/milky/concurrent/Futures.java diff --git a/milky-concurrent/src/main/java/cn/sliew/milky/concurrent/ProgressiveFuture.java b/milky-concurrent/milky-concurrent-future/src/main/java/cn/sliew/milky/concurrent/ProgressiveFuture.java similarity index 100% rename from milky-concurrent/src/main/java/cn/sliew/milky/concurrent/ProgressiveFuture.java rename to milky-concurrent/milky-concurrent-future/src/main/java/cn/sliew/milky/concurrent/ProgressiveFuture.java diff --git a/milky-concurrent/src/main/java/cn/sliew/milky/concurrent/ProgressiveFutureListener.java b/milky-concurrent/milky-concurrent-future/src/main/java/cn/sliew/milky/concurrent/ProgressiveFutureListener.java similarity index 100% rename from milky-concurrent/src/main/java/cn/sliew/milky/concurrent/ProgressiveFutureListener.java rename to milky-concurrent/milky-concurrent-future/src/main/java/cn/sliew/milky/concurrent/ProgressiveFutureListener.java diff --git a/milky-concurrent/src/main/java/cn/sliew/milky/concurrent/ProgressivePromise.java b/milky-concurrent/milky-concurrent-future/src/main/java/cn/sliew/milky/concurrent/ProgressivePromise.java similarity index 100% rename from milky-concurrent/src/main/java/cn/sliew/milky/concurrent/ProgressivePromise.java rename to milky-concurrent/milky-concurrent-future/src/main/java/cn/sliew/milky/concurrent/ProgressivePromise.java diff --git a/milky-concurrent/src/main/java/cn/sliew/milky/concurrent/Promise.java b/milky-concurrent/milky-concurrent-future/src/main/java/cn/sliew/milky/concurrent/Promise.java similarity index 100% rename from milky-concurrent/src/main/java/cn/sliew/milky/concurrent/Promise.java rename to milky-concurrent/milky-concurrent-future/src/main/java/cn/sliew/milky/concurrent/Promise.java diff --git a/milky-concurrent/src/main/java/cn/sliew/milky/concurrent/SucceededFuture.java b/milky-concurrent/milky-concurrent-future/src/main/java/cn/sliew/milky/concurrent/SucceededFuture.java similarity index 100% rename from milky-concurrent/src/main/java/cn/sliew/milky/concurrent/SucceededFuture.java rename to milky-concurrent/milky-concurrent-future/src/main/java/cn/sliew/milky/concurrent/SucceededFuture.java diff --git a/milky-thread/pom.xml b/milky-concurrent/milky-concurrent-thread/pom.xml similarity index 89% rename from milky-thread/pom.xml rename to milky-concurrent/milky-concurrent-thread/pom.xml index b52084b6..c339e87a 100644 --- a/milky-thread/pom.xml +++ b/milky-concurrent/milky-concurrent-thread/pom.xml @@ -5,12 +5,11 @@ 4.0.0 cn.sliew - milky-all - 0.0.14 + milky-concurrent + 1.0.14-SNAPSHOT ../pom.xml - milky-thread - ${project.artifactId} + milky-concurrent-thread true @@ -42,5 +41,4 @@ - \ No newline at end of file diff --git a/milky-thread/src/main/java/cn/sliew/milky/thread/ExecutorUtil.java b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/ExecutorUtil.java similarity index 94% rename from milky-thread/src/main/java/cn/sliew/milky/thread/ExecutorUtil.java rename to milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/ExecutorUtil.java index 553ec896..d6ee8167 100644 --- a/milky-thread/src/main/java/cn/sliew/milky/thread/ExecutorUtil.java +++ b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/ExecutorUtil.java @@ -1,4 +1,4 @@ -package cn.sliew.milky.thread; +package cn.sliew.milky.concurrent.thread; import java.util.concurrent.*; @@ -56,8 +56,8 @@ static int twiceProcessors() { * capacity value; a SynchronousQueue else. * @param queueCapacity the specified queue capacity * @return the BlockingQueue instance - * @see java.util.concurrent.LinkedBlockingQueue - * @see java.util.concurrent.SynchronousQueue + * @see LinkedBlockingQueue + * @see SynchronousQueue */ static BlockingQueue boundedQueue(int queueCapacity) { checkArgument(queueCapacity > 0, () -> "queueCapacity must greater than 0"); diff --git a/milky-thread/src/main/java/cn/sliew/milky/thread/MilkyThreadPoolExecutor.java b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/MilkyThreadPoolExecutor.java similarity index 94% rename from milky-thread/src/main/java/cn/sliew/milky/thread/MilkyThreadPoolExecutor.java rename to milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/MilkyThreadPoolExecutor.java index f5255d07..b9814520 100644 --- a/milky-thread/src/main/java/cn/sliew/milky/thread/MilkyThreadPoolExecutor.java +++ b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/MilkyThreadPoolExecutor.java @@ -1,7 +1,10 @@ -package cn.sliew.milky.thread; +package cn.sliew.milky.concurrent.thread; import cn.sliew.milky.common.collect.ConcurrentReferenceHashMap; -import cn.sliew.milky.thread.rejected.policy.AbortPolicyWithReport; +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; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -21,7 +24,7 @@ public class MilkyThreadPoolExecutor extends ThreadPoolExecutor { private final Object monitor = new Object(); - private RejectedExecutionHandler rejectedExecutionHandler = new ThreadPoolExecutor.AbortPolicy(); + private RejectedExecutionHandler rejectedExecutionHandler = new AbortPolicy(); private ThreadFactory threadFactory; @@ -104,7 +107,11 @@ public void execute(Runnable command) { try { ((RunnableWrapper) command).onRejection(ex); } finally { - ((RunnableWrapper) command).onAfter(); + try { + ((RunnableWrapper) command).onAfter(); + } catch (Exception e) { + Rethrower.throwAs(e); + } } } else { throw ex; diff --git a/milky-thread/src/main/java/cn/sliew/milky/thread/ResizableBlockingQueue.java b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/ResizableBlockingQueue.java similarity index 97% rename from milky-thread/src/main/java/cn/sliew/milky/thread/ResizableBlockingQueue.java rename to milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/ResizableBlockingQueue.java index ccb7f6d0..d4c182cf 100644 --- a/milky-thread/src/main/java/cn/sliew/milky/thread/ResizableBlockingQueue.java +++ b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/ResizableBlockingQueue.java @@ -1,4 +1,4 @@ -package cn.sliew.milky.thread; +package cn.sliew.milky.concurrent.thread; import java.util.concurrent.BlockingQueue; diff --git a/milky-thread/src/main/java/cn/sliew/milky/thread/SizeBlockingQueue.java b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/SizeBlockingQueue.java similarity index 99% rename from milky-thread/src/main/java/cn/sliew/milky/thread/SizeBlockingQueue.java rename to milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/SizeBlockingQueue.java index 3663f37b..636d7231 100644 --- a/milky-thread/src/main/java/cn/sliew/milky/thread/SizeBlockingQueue.java +++ b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/SizeBlockingQueue.java @@ -1,4 +1,4 @@ -package cn.sliew.milky.thread; +package cn.sliew.milky.concurrent.thread; import java.util.AbstractQueue; import java.util.Collection; diff --git a/milky-thread/src/main/java/cn/sliew/milky/thread/TaskDecorator.java b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/TaskDecorator.java similarity index 92% rename from milky-thread/src/main/java/cn/sliew/milky/thread/TaskDecorator.java rename to milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/TaskDecorator.java index 6becf83d..08a9c2f1 100644 --- a/milky-thread/src/main/java/cn/sliew/milky/thread/TaskDecorator.java +++ b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/TaskDecorator.java @@ -1,4 +1,4 @@ -package cn.sliew.milky.thread; +package cn.sliew.milky.concurrent.thread; /** * A callback interface for a decorator to be applied to any {@link Runnable} diff --git a/milky-thread/src/main/java/cn/sliew/milky/thread/ThreadContext.java b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/ThreadContext.java similarity index 98% rename from milky-thread/src/main/java/cn/sliew/milky/thread/ThreadContext.java rename to milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/ThreadContext.java index a493e0c6..b0e63191 100644 --- a/milky-thread/src/main/java/cn/sliew/milky/thread/ThreadContext.java +++ b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/ThreadContext.java @@ -1,7 +1,8 @@ -package cn.sliew.milky.thread; +package cn.sliew.milky.concurrent.thread; -import cn.sliew.milky.thread.context.DefaultThreadContextMap; -import cn.sliew.milky.thread.context.DefaultThreadContextStack; + +import cn.sliew.milky.concurrent.thread.context.DefaultThreadContextMap; +import cn.sliew.milky.concurrent.thread.context.DefaultThreadContextStack; import java.util.Collection; import java.util.Collections; diff --git a/milky-thread/src/main/java/cn/sliew/milky/thread/ThreadContextMap.java b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/ThreadContextMap.java similarity index 97% rename from milky-thread/src/main/java/cn/sliew/milky/thread/ThreadContextMap.java rename to milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/ThreadContextMap.java index c24a3b73..1c15dc02 100644 --- a/milky-thread/src/main/java/cn/sliew/milky/thread/ThreadContextMap.java +++ b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/ThreadContextMap.java @@ -1,4 +1,4 @@ -package cn.sliew.milky.thread; +package cn.sliew.milky.concurrent.thread; import java.util.Map; diff --git a/milky-thread/src/main/java/cn/sliew/milky/thread/ThreadContextStack.java b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/ThreadContextStack.java similarity index 97% rename from milky-thread/src/main/java/cn/sliew/milky/thread/ThreadContextStack.java rename to milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/ThreadContextStack.java index 624d5c65..1c64f225 100644 --- a/milky-thread/src/main/java/cn/sliew/milky/thread/ThreadContextStack.java +++ b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/ThreadContextStack.java @@ -1,4 +1,4 @@ -package cn.sliew.milky.thread; +package cn.sliew.milky.concurrent.thread; import java.io.Serializable; import java.util.*; @@ -19,7 +19,7 @@ public interface ThreadContextStack extends Collection, Serializable { * Returns the element at the top of the stack. * * @return The element at the top of the stack. - * @throws java.util.NoSuchElementException if the stack is empty. + * @throws NoSuchElementException if the stack is empty. */ String pop(); diff --git a/milky-thread/src/main/java/cn/sliew/milky/thread/ThreadEagerQueue.java b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/ThreadEagerQueue.java similarity index 93% rename from milky-thread/src/main/java/cn/sliew/milky/thread/ThreadEagerQueue.java rename to milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/ThreadEagerQueue.java index 579b93a1..cf9c93f0 100644 --- a/milky-thread/src/main/java/cn/sliew/milky/thread/ThreadEagerQueue.java +++ b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/ThreadEagerQueue.java @@ -1,4 +1,4 @@ -package cn.sliew.milky.thread; +package cn.sliew.milky.concurrent.thread; import java.util.concurrent.LinkedTransferQueue; import java.util.concurrent.ThreadPoolExecutor; diff --git a/milky-thread/src/main/java/cn/sliew/milky/thread/ThreadPoolConfigEnum.java b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/ThreadPoolConfigEnum.java similarity index 97% rename from milky-thread/src/main/java/cn/sliew/milky/thread/ThreadPoolConfigEnum.java rename to milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/ThreadPoolConfigEnum.java index c992fd98..9b58a70f 100644 --- a/milky-thread/src/main/java/cn/sliew/milky/thread/ThreadPoolConfigEnum.java +++ b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/ThreadPoolConfigEnum.java @@ -1,4 +1,4 @@ -package cn.sliew.milky.thread; +package cn.sliew.milky.concurrent.thread; import java.util.Collections; import java.util.HashMap; diff --git a/milky-thread/src/main/java/cn/sliew/milky/thread/ThreadPoolExecutorBuilder.java b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/ThreadPoolExecutorBuilder.java similarity index 93% rename from milky-thread/src/main/java/cn/sliew/milky/thread/ThreadPoolExecutorBuilder.java rename to milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/ThreadPoolExecutorBuilder.java index 58e764d2..d49988e6 100644 --- a/milky-thread/src/main/java/cn/sliew/milky/thread/ThreadPoolExecutorBuilder.java +++ b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/ThreadPoolExecutorBuilder.java @@ -1,9 +1,10 @@ -package cn.sliew.milky.thread; +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.thread.metrics.ThreadPoolExecutorMetrics; -import cn.sliew.milky.thread.rejected.policy.AbortPolicyWithReport; +import cn.sliew.milky.concurrent.thread.metrics.ThreadPoolExecutorMetrics; +import cn.sliew.milky.concurrent.thread.policy.AbortPolicyWithReport; import io.micrometer.core.instrument.MeterRegistry; import java.util.concurrent.BlockingQueue; diff --git a/milky-thread/src/main/java/cn/sliew/milky/thread/ThreadPoolManager.java b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/ThreadPoolManager.java similarity index 89% rename from milky-thread/src/main/java/cn/sliew/milky/thread/ThreadPoolManager.java rename to milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/ThreadPoolManager.java index d7e06746..25dc6232 100644 --- a/milky-thread/src/main/java/cn/sliew/milky/thread/ThreadPoolManager.java +++ b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/ThreadPoolManager.java @@ -1,4 +1,4 @@ -package cn.sliew.milky.thread; +package cn.sliew.milky.concurrent.thread; import java.util.concurrent.TimeUnit; diff --git a/milky-thread/src/main/java/cn/sliew/milky/thread/ThreadPoolType.java b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/ThreadPoolType.java similarity index 95% rename from milky-thread/src/main/java/cn/sliew/milky/thread/ThreadPoolType.java rename to milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/ThreadPoolType.java index ec5faf17..522ebdcd 100644 --- a/milky-thread/src/main/java/cn/sliew/milky/thread/ThreadPoolType.java +++ b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/ThreadPoolType.java @@ -1,4 +1,4 @@ -package cn.sliew.milky.thread; +package cn.sliew.milky.concurrent.thread; import java.util.Collections; import java.util.HashMap; diff --git a/milky-thread/src/main/java/cn/sliew/milky/thread/XRejectedExecutionHandler.java b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/XRejectedExecutionHandler.java similarity index 83% rename from milky-thread/src/main/java/cn/sliew/milky/thread/XRejectedExecutionHandler.java rename to milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/XRejectedExecutionHandler.java index 7a2031ec..33de6ed9 100644 --- a/milky-thread/src/main/java/cn/sliew/milky/thread/XRejectedExecutionHandler.java +++ b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/XRejectedExecutionHandler.java @@ -1,4 +1,4 @@ -package cn.sliew.milky.thread; +package cn.sliew.milky.concurrent.thread; import java.util.concurrent.RejectedExecutionHandler; diff --git a/milky-thread/src/main/java/cn/sliew/milky/thread/context/DefaultThreadContextMap.java b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/context/DefaultThreadContextMap.java similarity index 96% rename from milky-thread/src/main/java/cn/sliew/milky/thread/context/DefaultThreadContextMap.java rename to milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/context/DefaultThreadContextMap.java index 713807d4..fea7496c 100644 --- a/milky-thread/src/main/java/cn/sliew/milky/thread/context/DefaultThreadContextMap.java +++ b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/context/DefaultThreadContextMap.java @@ -1,7 +1,7 @@ -package cn.sliew.milky.thread.context; +package cn.sliew.milky.concurrent.thread.context; -import cn.sliew.milky.thread.ThreadContext; -import cn.sliew.milky.thread.ThreadContextMap; +import cn.sliew.milky.concurrent.thread.ThreadContext; +import cn.sliew.milky.concurrent.thread.ThreadContextMap; import java.util.Collections; import java.util.HashMap; diff --git a/milky-thread/src/main/java/cn/sliew/milky/thread/context/DefaultThreadContextStack.java b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/context/DefaultThreadContextStack.java similarity index 96% rename from milky-thread/src/main/java/cn/sliew/milky/thread/context/DefaultThreadContextStack.java rename to milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/context/DefaultThreadContextStack.java index e833d016..c584f9b4 100644 --- a/milky-thread/src/main/java/cn/sliew/milky/thread/context/DefaultThreadContextStack.java +++ b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/context/DefaultThreadContextStack.java @@ -1,9 +1,12 @@ -package cn.sliew.milky.thread.context; +package cn.sliew.milky.concurrent.thread.context; -import cn.sliew.milky.thread.ThreadContext; -import cn.sliew.milky.thread.ThreadContextStack; +import cn.sliew.milky.concurrent.thread.ThreadContext; +import cn.sliew.milky.concurrent.thread.ThreadContextStack; -import java.util.*; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; public class DefaultThreadContextStack implements ThreadContextStack { diff --git a/milky-thread/src/main/java/cn/sliew/milky/thread/context/MutableThreadContextStack.java b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/context/MutableThreadContextStack.java similarity index 97% rename from milky-thread/src/main/java/cn/sliew/milky/thread/context/MutableThreadContextStack.java rename to milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/context/MutableThreadContextStack.java index 388972c3..7fdca208 100644 --- a/milky-thread/src/main/java/cn/sliew/milky/thread/context/MutableThreadContextStack.java +++ b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/context/MutableThreadContextStack.java @@ -1,7 +1,7 @@ -package cn.sliew.milky.thread.context; +package cn.sliew.milky.concurrent.thread.context; -import cn.sliew.milky.thread.ThreadContext; -import cn.sliew.milky.thread.ThreadContextStack; +import cn.sliew.milky.concurrent.thread.ThreadContext; +import cn.sliew.milky.concurrent.thread.ThreadContextStack; import java.util.ArrayList; import java.util.Collection; diff --git a/milky-thread/src/main/java/cn/sliew/milky/thread/metrics/ThreadPoolExecutorMetrics.java b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/metrics/ThreadPoolExecutorMetrics.java similarity index 96% rename from milky-thread/src/main/java/cn/sliew/milky/thread/metrics/ThreadPoolExecutorMetrics.java rename to milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/metrics/ThreadPoolExecutorMetrics.java index 99b8fb07..ba74e005 100644 --- a/milky-thread/src/main/java/cn/sliew/milky/thread/metrics/ThreadPoolExecutorMetrics.java +++ b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/metrics/ThreadPoolExecutorMetrics.java @@ -1,6 +1,6 @@ -package cn.sliew.milky.thread.metrics; +package cn.sliew.milky.concurrent.thread.metrics; -import cn.sliew.milky.thread.MilkyThreadPoolExecutor; +import cn.sliew.milky.concurrent.thread.MilkyThreadPoolExecutor; import io.micrometer.core.instrument.FunctionCounter; import io.micrometer.core.instrument.Gauge; import io.micrometer.core.instrument.MeterRegistry; diff --git a/milky-thread/src/main/java/cn/sliew/milky/thread/rejected/policy/AbortPolicyWithReport.java b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/policy/AbortPolicyWithReport.java similarity index 95% rename from milky-thread/src/main/java/cn/sliew/milky/thread/rejected/policy/AbortPolicyWithReport.java rename to milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/policy/AbortPolicyWithReport.java index fcd19791..e746323e 100644 --- a/milky-thread/src/main/java/cn/sliew/milky/thread/rejected/policy/AbortPolicyWithReport.java +++ b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/policy/AbortPolicyWithReport.java @@ -1,8 +1,8 @@ -package cn.sliew.milky.thread.rejected.policy; +package cn.sliew.milky.concurrent.thread.policy; -import cn.sliew.milky.thread.RunnableWrapper; -import cn.sliew.milky.thread.SizeBlockingQueue; -import cn.sliew.milky.thread.XRejectedExecutionHandler; +import cn.sliew.milky.common.concurrent.RunnableWrapper; +import cn.sliew.milky.concurrent.thread.SizeBlockingQueue; +import cn.sliew.milky.concurrent.thread.XRejectedExecutionHandler; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; diff --git a/milky-thread/src/main/java/cn/sliew/milky/thread/rejected/policy/JVMUtil.java b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/policy/JVMUtil.java similarity index 98% rename from milky-thread/src/main/java/cn/sliew/milky/thread/rejected/policy/JVMUtil.java rename to milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/policy/JVMUtil.java index bc2ada72..9d13248d 100644 --- a/milky-thread/src/main/java/cn/sliew/milky/thread/rejected/policy/JVMUtil.java +++ b/milky-concurrent/milky-concurrent-thread/src/main/java/cn/sliew/milky/concurrent/thread/policy/JVMUtil.java @@ -1,4 +1,4 @@ -package cn.sliew.milky.thread.rejected.policy; +package cn.sliew.milky.concurrent.thread.policy; import java.io.OutputStream; import java.lang.management.*; diff --git a/milky-concurrent/pom.xml b/milky-concurrent/pom.xml index b6bc6927..1cfd96e0 100644 --- a/milky-concurrent/pom.xml +++ b/milky-concurrent/pom.xml @@ -10,23 +10,16 @@ ../pom.xml milky-concurrent - jar + pom ${project.artifactId} + + milky-concurrent-thread + milky-concurrent-future + + true - - - cn.sliew - milky-common - - - cn.sliew - milky-test - test - - - \ No newline at end of file diff --git a/milky-concurrent/src/main/java/cn/sliew/milky/concurrent/threadpool/DaemonThreadFactory.java b/milky-concurrent/src/main/java/cn/sliew/milky/concurrent/threadpool/DaemonThreadFactory.java deleted file mode 100644 index 92cc669c..00000000 --- a/milky-concurrent/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-thread/src/main/java/cn/sliew/milky/thread/RunnableWrapper.java b/milky-thread/src/main/java/cn/sliew/milky/thread/RunnableWrapper.java deleted file mode 100644 index adda7538..00000000 --- a/milky-thread/src/main/java/cn/sliew/milky/thread/RunnableWrapper.java +++ /dev/null @@ -1,62 +0,0 @@ -package cn.sliew.milky.thread; - -import java.util.concurrent.RejectedExecutionException; - -/** - * An extension to runnable. - */ -public interface RunnableWrapper extends Runnable { - - @Override - default void run() { - try { - doRun(); - } catch (RejectedExecutionException t) { - onRejection(t); - } catch (Exception t) { - onFailure(t); - } finally { - onAfter(); - } - } - - /** - * This method has the same semantics as {@link Runnable#run()} - * - * @throws InterruptedException if the run method throws an InterruptedException - */ - void doRun() throws Exception; - - /** - * This method is called in a finally block after successful execution - * or on a rejection. - * - * @see MilkyThreadPoolExecutor#execute(java.lang.Runnable) - */ - default void onAfter() { - // nothing by default - } - - /** - * This method is invoked for all exception thrown by {@link #doRun()} - */ - void onFailure(Exception e); - - /** - * This should be executed if the thread-pool executing this action rejected the execution. - * The default implementation forwards to {@link #onFailure(Exception)} - * - * @see MilkyThreadPoolExecutor#execute(java.lang.Runnable) - */ - default void onRejection(Exception e) { - onFailure(e); - } - - /** - * Should the runnable force its execution in case it gets rejected? - */ - default boolean isForceExecution() { - return false; - } - -} diff --git a/milky/pom.xml b/milky/pom.xml index 05d8c7be..222ee5c9 100644 --- a/milky/pom.xml +++ b/milky/pom.xml @@ -24,10 +24,6 @@ cn.sliew milky-common - - cn.sliew - milky-concurrent - cn.sliew milky-test diff --git a/pom.xml b/pom.xml index cc7c2e64..12cbec9f 100644 --- a/pom.xml +++ b/pom.xml @@ -63,7 +63,6 @@ milky-serialize milky-log milky-event - milky-thread milky-config milky-io milky-dsl @@ -80,31 +79,60 @@ ${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} - ${project.groupId} - milky-common - ${project.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-log + milky-common ${project.version} ${project.groupId} - milky-concurrent + milky-log ${project.version} @@ -118,33 +146,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} @@ -368,6 +400,23 @@ **/package-info.java + + + org.projectlombok + lombok + ${lombok.version} + + + org.mapstruct + mapstruct-processor + ${mapstruct.version} + + + org.projectlombok + lombok-mapstruct-binding + ${mapstruct.lombok.binding.version} + +