定时器算法

   @Scheduled(cron = "0 0/1 * * * ?")
public void planAutoCreateTaskSchedule() {
List<UiPolicyEntity> uiPolicyEntities = uiPolicyService.getAllWithCron();
uiPolicyEntities.forEach(uiPolicyEntity -> {
String cron = uiPolicyEntity.getCronTab();
if (!StringUtils.isBlank(cron) && uiPolicyEntity.getState() == 1){
Date curTime = new Date();
CronExpression cronExpression = null;
try {
cronExpression = new CronExpression(cron);
} catch (ParseException e) {
e.printStackTrace();
}
Date newDate = cronExpression.getNextValidTimeAfter(curTime);
if ((newDate.getTime() - curTime.getTime()) < (60 * 1000)) {
            ...
}
}
});
}
posted @ 2021-01-14 15:48  GᎭ•Cristin  阅读(131)  评论(0编辑  收藏  举报