area transfer

master
alis-lc 3 years ago
parent cbd7afee8a
commit 05b1bd2b88

@ -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());
}
}

@ -1,6 +1,7 @@
package org.alis.aliscomponent.executor; package org.alis.aliscomponent.executor;
import io.netty.util.HashedWheelTimer; import io.netty.util.HashedWheelTimer;
import io.netty.util.Timeout;
import io.netty.util.Timer; import io.netty.util.Timer;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -24,13 +25,14 @@ public class NettyTimerWheelDelayExecutor implements TimeWheelDelayExecutor {
@Override @Override
public void scheduleWithFixedDelay(Runnable command, long delay, TimeUnit unit) { public void scheduleWithFixedDelay(Runnable command, long delay, TimeUnit unit) {
timer.newTimeout(timeout -> { Timeout timeout1 = timer.newTimeout(timeout -> {
try { try {
command.run(); command.run();
} finally { } finally {
timer.newTimeout(time -> scheduleWithFixedDelay(command, delay, unit), delay, unit); timer.newTimeout(time -> scheduleWithFixedDelay(command, delay, unit), delay, unit);
} }
}, delay, unit); }, delay, unit);
} }
@Override @Override

@ -3,6 +3,7 @@ package org.alis.smallcc.algorithm.timewheel.netty;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import io.netty.util.HashedWheelTimer; import io.netty.util.HashedWheelTimer;
import io.netty.util.Timeout;
import io.netty.util.Timer; import io.netty.util.Timer;
public class Main { public class Main {
@ -10,7 +11,7 @@ public class Main {
private static Integer i = 0; private static Integer i = 0;
public static void main(String[] args) { public static void main(String[] args) throws InterruptedException {
// Timer timer = new HashedWheelTimer(); // Timer timer = new HashedWheelTimer();
// //
// // 重复执行 // // 重复执行
@ -25,10 +26,21 @@ public class Main {
// //
// 分钟盘 // 分钟盘
Timer timer = new HashedWheelTimer(1L, TimeUnit.SECONDS, 60); Timer timer = new HashedWheelTimer(1L, TimeUnit.SECONDS, 60);
timer.newTimeout(timeout -> { // timer.newTimeout(timeout -> {
System.out.println("重复任务执行器" + timeout.getClass().getSimpleName()+i); // System.out.println("重复任务执行器" + timeout.getClass().getSimpleName() + i);
i++; // i++;
timer.newTimeout(timeout.task(), 1L, TimeUnit.SECONDS); // timer.newTimeout(timeout.task(), 1L, TimeUnit.SECONDS);
}, 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();
} }
} }

Loading…
Cancel
Save