refactor(scheduler):优化任务调度时间环逻辑

- 添加 refreshNextValidTime 方法注释
- 使用 computeIfAbsent 简化时间环数据初始化- 更新日志输出格式为 List.of
-优化时间环数据空值判断逻辑
pull/72/head
xuxueli 2 months ago
parent 89563da2ac
commit 8785b3f516

@ -228,6 +228,12 @@ public class JobScheduleHelper {
ringThread.start();
}
/**
* refresh next valid time of job
*
* @param jobInfo job info
* @param fromTime from time
*/
private void refreshNextValidTime(XxlJobInfo jobInfo, Date fromTime) {
try {
Date nextValidTime = generateNextValidTime(jobInfo, fromTime);
@ -254,16 +260,21 @@ public class JobScheduleHelper {
}
}
/**
* push time ring
*
* @param ringSecond ring second
* @param jobId job id
*/
private void pushTimeRing(int ringSecond, int jobId){
// push async ring
List<Integer> ringItemData = ringData.get(ringSecond);
if (ringItemData == null) {
ringItemData = new ArrayList<Integer>();
ringData.put(ringSecond, ringItemData);
}
ringItemData.add(jobId);
// get ringItemData, init when not exists
List<Integer> ringItemData = ringData.computeIfAbsent(
ringSecond,
k -> new ArrayList<>());
logger.debug(">>>>>>>>>>> xxl-job, schedule push time-ring : " + ringSecond + " = " + Arrays.asList(ringItemData) );
// push async rind
ringItemData.add(jobId);
logger.debug(">>>>>>>>>>> xxl-job, schedule push time-ring : " + ringSecond + " = " + List.of(ringItemData));
}
/**
@ -293,7 +304,7 @@ public class JobScheduleHelper {
if (!ringData.isEmpty()) {
for (int second : ringData.keySet()) {
List<Integer> tmpData = ringData.get(second);
if (tmpData!=null && tmpData.size()>0) {
if (tmpData!=null && !tmpData.isEmpty()) {
hasRingData = true;
break;
}

Loading…
Cancel
Save