diff --git a/alis-artemis/src/test/java/org/alis/artemis/ApplicationTest.java b/alis-artemis/src/test/java/org/alis/artemis/ApplicationTest.java new file mode 100644 index 0000000..a9c8761 --- /dev/null +++ b/alis-artemis/src/test/java/org/alis/artemis/ApplicationTest.java @@ -0,0 +1,31 @@ +package org.alis.artemis; + +import org.junit.jupiter.api.Test; + +import java.time.*; + +public class ApplicationTest { + + @Test + public void test() { + + System.out.println(LocalDateTime.now()); + + String zoneId = ZoneId.systemDefault().getId(); + System.out.println(zoneId); + + LocalDateTime utc = LocalDateTime.now(ZoneOffset.UTC); + System.out.println(utc); + + + ZoneId of = ZoneId.of(zoneId); + ZonedDateTime zonedDateTime1 = utc.atZone(ZoneOffset.UTC).withZoneSameInstant(of); + + + + System.out.println(zonedDateTime1.toLocalDateTime()); + + + } + +} diff --git a/alis-component/src/main/java/org/alis/aliscomponent/executor/NettyTimerWheelDelayExecutor.java b/alis-component/src/main/java/org/alis/aliscomponent/executor/NettyTimerWheelDelayExecutor.java index 2ec89a3..234bdcc 100644 --- a/alis-component/src/main/java/org/alis/aliscomponent/executor/NettyTimerWheelDelayExecutor.java +++ b/alis-component/src/main/java/org/alis/aliscomponent/executor/NettyTimerWheelDelayExecutor.java @@ -1,6 +1,7 @@ package org.alis.aliscomponent.executor; import io.netty.util.HashedWheelTimer; +import io.netty.util.Timeout; import io.netty.util.Timer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -24,13 +25,14 @@ public class NettyTimerWheelDelayExecutor implements TimeWheelDelayExecutor { @Override public void scheduleWithFixedDelay(Runnable command, long delay, TimeUnit unit) { - timer.newTimeout(timeout -> { + Timeout timeout1 = timer.newTimeout(timeout -> { try { command.run(); } finally { timer.newTimeout(time -> scheduleWithFixedDelay(command, delay, unit), delay, unit); } }, delay, unit); + } @Override diff --git a/datastructure/src/main/java/org/alis/smallcc/algorithm/timewheel/netty/Main.java b/datastructure/src/main/java/org/alis/smallcc/algorithm/timewheel/netty/Main.java index b827d66..fadce54 100644 --- a/datastructure/src/main/java/org/alis/smallcc/algorithm/timewheel/netty/Main.java +++ b/datastructure/src/main/java/org/alis/smallcc/algorithm/timewheel/netty/Main.java @@ -3,14 +3,15 @@ package org.alis.smallcc.algorithm.timewheel.netty; import java.util.concurrent.TimeUnit; import io.netty.util.HashedWheelTimer; +import io.netty.util.Timeout; import io.netty.util.Timer; public class Main { - - private static Integer i = 0; - - public static void main(String[] args) { + private static Integer i = 0; + + + public static void main(String[] args) throws InterruptedException { // Timer timer = new HashedWheelTimer(); // // // 重复执行 @@ -24,11 +25,22 @@ public class Main { // }, 10L, TimeUnit.SECONDS); // // 分钟盘 - Timer timer = new HashedWheelTimer(1L,TimeUnit.SECONDS,60); - timer.newTimeout(timeout -> { - System.out.println("重复任务执行器" + timeout.getClass().getSimpleName()+i); - i++; - timer.newTimeout(timeout.task(), 1L, TimeUnit.SECONDS); - }, 1L, TimeUnit.SECONDS); + Timer timer = new HashedWheelTimer(1L, TimeUnit.SECONDS, 60); +// timer.newTimeout(timeout -> { +// System.out.println("重复任务执行器" + timeout.getClass().getSimpleName() + i); +// i++; +// timer.newTimeout(timeout.task(), 1L, TimeUnit.SECONDS); +// }, 1L, TimeUnit.SECONDS); + + Timeout timeout1 = timer.newTimeout(timeout -> { + while (true) { + System.out.println("重复任务执行器" + timeout.getClass().getSimpleName() + "执行状态" + timeout.isCancelled()); + Thread.sleep(1000L); + } + }, 3L, TimeUnit.SECONDS); + + TimeUnit.SECONDS.sleep(1L); + timeout1.cancel(); + } }