mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
commit
7b31fc5fc3
@ -72,6 +72,7 @@ public class TimingWheel {
|
|||||||
this.wheelSize = wheelSize;
|
this.wheelSize = wheelSize;
|
||||||
this.interval = tickMs * wheelSize;
|
this.interval = tickMs * wheelSize;
|
||||||
this.timerTaskLists = new TimerTaskList[wheelSize];
|
this.timerTaskLists = new TimerTaskList[wheelSize];
|
||||||
|
initTimerTaskList();
|
||||||
//currentTime为tickMs的整数倍 这里做取整操作
|
//currentTime为tickMs的整数倍 这里做取整操作
|
||||||
this.currentTime = currentTime - (currentTime % tickMs);
|
this.currentTime = currentTime - (currentTime % tickMs);
|
||||||
this.consumer = consumer;
|
this.consumer = consumer;
|
||||||
@ -93,12 +94,7 @@ public class TimingWheel {
|
|||||||
long virtualId = expiration / tickMs;
|
long virtualId = expiration / tickMs;
|
||||||
int index = (int) (virtualId % wheelSize);
|
int index = (int) (virtualId % wheelSize);
|
||||||
StaticLog.debug("tickMs: {} ------index: {} ------expiration: {}", tickMs, index, expiration);
|
StaticLog.debug("tickMs: {} ------index: {} ------expiration: {}", tickMs, index, expiration);
|
||||||
|
|
||||||
TimerTaskList timerTaskList = timerTaskLists[index];
|
TimerTaskList timerTaskList = timerTaskLists[index];
|
||||||
if (null == timerTaskList) {
|
|
||||||
timerTaskList = new TimerTaskList();
|
|
||||||
timerTaskLists[index] = timerTaskList;
|
|
||||||
}
|
|
||||||
timerTaskList.addTask(timerTask);
|
timerTaskList.addTask(timerTask);
|
||||||
if (timerTaskList.setExpiration(virtualId * tickMs)) {
|
if (timerTaskList.setExpiration(virtualId * tickMs)) {
|
||||||
//添加到delayQueue中
|
//添加到delayQueue中
|
||||||
@ -140,4 +136,13 @@ public class TimingWheel {
|
|||||||
}
|
}
|
||||||
return overflowWheel;
|
return overflowWheel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始 timerTaskLists
|
||||||
|
*/
|
||||||
|
private void initTimerTaskList() {
|
||||||
|
for (int i = 0; i < this.timerTaskLists.length; i++) {
|
||||||
|
this.timerTaskLists[i] = new TimerTaskList();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user