This commit is contained in:
Looly
2024-01-11 13:31:10 +08:00
parent f341b9ed7a
commit fe2516b646
5 changed files with 16 additions and 10 deletions

View File

@@ -13,6 +13,7 @@
package org.dromara.hutool.cron;
import org.dromara.hutool.core.date.DateUnit;
import org.dromara.hutool.core.lang.Console;
import org.dromara.hutool.core.thread.ThreadUtil;
import org.dromara.hutool.log.Log;
@@ -63,9 +64,14 @@ public class CronTimer extends Thread implements Serializable {
//等待直到下一个时间点如果被中断直接退出Timer
break;
}
//执行点,时间记录为执行开始的时间,而非结束时间
thisTime = System.currentTimeMillis();
spawnLauncher(thisTime);
spawnLauncher(nextTime);
// issue#3460 采用叠加方式确保正好是1分钟或1秒避免sleep晚醒问题
// 此处无需校验因为每次循环都是sleep与上触发点的时间差。
// 当上一次晚醒后本次会减少sleep时间保证误差在一个unit内并不断修正。
thisTime = nextTime;
} else{
// 非正常时间重新计算issue#1224@Github
thisTime = System.currentTimeMillis();

View File

@@ -8,7 +8,7 @@
# demo.org.dromara.hutool.cron.TestJob.doTest = */1 * * * * *
[org.dromara.hutool.cron.demo]=
[org.dromara.hutool.cron.demo]
# 6位表达式在秒匹配模式下可用此处表示每秒执行一次
# TestJob.doTest = */1 * * * * *
# 5位表达式在分匹配模式下可用此处表示每分钟执行一次