package com.cmcc.open.ota.config; import io.netty.util.HashedWheelTimer; import io.netty.util.Timeout; import io.netty.util.TimerTask; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import java.util.concurrent.TimeUnit; @Slf4j @Component public class DelayTaskDemo { public static void main(String[] args) { log.info("main start"); TimerTask task = new TimerTask() { @Override public void run(Timeout timeout) throws Exception { log.info("延时任务开始执行咯。。。"); } }; runDelayTask(task, 10, TimeUnit.SECONDS); } private static final HashedWheelTimer timer = new HashedWheelTimer(); public static void runDelayTask(TimerTask task, long delay, TimeUnit unit) { timer.newTimeout(task, delay, unit); } }
标签:Netty,task,HashedWheelTimer,util,TimerTask,import,public,延迟 From: https://www.cnblogs.com/wuyun-blog/p/17058600.html