创建并启动时间轮
HashedWheelTimer timer = new HashedWheelTimer();
timer.start();
提交时间轮任务
Timeout timeout = timer.newTimeout(new Task(), 30, TimeUnit.MILLISECONDS);
30毫秒后自动执行时间轮任务
public class Task implements TimerTask {
@Override
public void run(Timeout timeout) throws Exception {
System.out.println("执行任务");
}
}
记录一下。