ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
判断一个cron表达式, 是不是今天需要执行, 主要是使用方法getNextValidTimeAfter 来根据传的时间获取下一次有效的运行时间, 这个也能判断当前时间是不是已经执行过任务 ``` DateUtils 是公司二次封装org.apache.commons.lang3.time的工具类 CronExpression 是 org.quartz.CronExpression public static Boolean isToday(String cronExpression) { try { CronExpression cron = new CronExpression(cronExpression); // 从今天0点开始, 获取最近的下一次运行时间 Date nextInvalidTimeAfter = cron.getNextValidTimeAfter(DateUtils.parseDate(LocalDate.now())); // 判断日期是不是同一天 return DateUtils.isSameDay(nextInvalidTimeAfter, new Date()); } catch (ParseException e) { throw new IllegalArgumentException(e.getMessage()); } } ``` ## 遇见的定时任务错误 Caused by: org.quartz.SchedulerException: Based on configured schedule, the given trigger 'DEFAULT.TASK_CLASS_NAME106' will never fire. 系统部署报这个错误, 用备份的正常启动成功的jar也提示这个错误, 然后看这个提示是定时任务有问题, 去sql里查看定时任务列表, 发现有暂停的定时任务设置的运行时间是 xxxx年, 然后正好现在是下一年, 定时任务永远也无法执行, 删除此任务 成功运行