超时时间轮---完成,测试有1ms误差,在找原因

This commit is contained in:
shenkaiwen5
2021-11-16 00:45:09 +08:00
parent 1a590cf691
commit f5e1b18a71
2 changed files with 6 additions and 3 deletions

View File

@@ -99,8 +99,11 @@ public class TimeWheel {
timerTaskList.addTask(timerTask);
if (timerTaskList.setExpiration(virtualId * tickMs)) {
//添加到delayList中
//TODO 改成加到list对应元素
delayList.get(overflowIndex).add(timerTaskList);
//TODO 改成加到list对应元素 【20槽, 时间轮层数】,这里添加前一定要初始化到对应层数
while (delayList.get(index).size() < overflowIndex + 1) {
delayList.get(index).add(timerTaskList);
}
delayList.get(index).set(overflowIndex, timerTaskList);
}
} else {
//放到上一层的时间轮

View File

@@ -41,7 +41,7 @@ public class Test {
.callback(w)
.build();
workerWrapper.setDelayMs(1002L);
workerWrapper.setDelayMs(1003L);
//虽然尚未执行但是也可以先取得结果的引用作为下一个任务的入参。V1.2前写法,需要手工给
//V1.3后不用给wrapper setParam了直接在worker的action里自行根据id获取即可.参考dependnew包下代码