Commit 7eaddd16f9cec7a4eab5bf036fb56e9efd2b20f0
1 parent
e06fc835
【修复】定时任务指定某一年执行时,只会执行一次,后台查看任务详细会报错
Showing
1 changed file
with
4 additions
and
4 deletions
yudao-framework/yudao-spring-boot-starter-job/src/main/java/cn/iocoder/yudao/framework/quartz/core/util/CronUtils.java
| ... | ... | @@ -34,24 +34,24 @@ public class CronUtils { |
| 34 | 34 | * @return 满足条件的执行时间 |
| 35 | 35 | */ |
| 36 | 36 | public static List<LocalDateTime> getNextTimes(String cronExpression, int n) { |
| 37 | - // 获得 CronExpression 对象 | |
| 37 | + // 1. 获得 CronExpression 对象 | |
| 38 | 38 | CronExpression cron; |
| 39 | 39 | try { |
| 40 | 40 | cron = new CronExpression(cronExpression); |
| 41 | 41 | } catch (ParseException e) { |
| 42 | 42 | throw new IllegalArgumentException(e.getMessage()); |
| 43 | 43 | } |
| 44 | - // 从当前开始计算,n 个满足条件的 | |
| 44 | + // 2. 从当前开始计算,n 个满足条件的 | |
| 45 | 45 | Date now = new Date(); |
| 46 | 46 | List<LocalDateTime> nextTimes = new ArrayList<>(n); |
| 47 | 47 | for (int i = 0; i < n; i++) { |
| 48 | 48 | Date nextTime = cron.getNextValidTimeAfter(now); |
| 49 | + // 2.1 如果 nextTime 为 null,说明没有更多的有效时间,退出循环 | |
| 49 | 50 | if (nextTime == null) { |
| 50 | - // 如果 nextTime 为 null,说明没有更多的有效时间,退出循环 | |
| 51 | 51 | break; |
| 52 | 52 | } |
| 53 | 53 | nextTimes.add(LocalDateTimeUtil.of(nextTime)); |
| 54 | - // 切换现在,为下一个触发时间; | |
| 54 | + // 2.2 切换现在,为下一个触发时间; | |
| 55 | 55 | now = nextTime; |
| 56 | 56 | } |
| 57 | 57 | return nextTimes; | ... | ... |