我想在每个假月的00:01:01打电话给我的工作。为此,我实现了org.springframework.scheduling.Trigger
界面,并在假月份的第一天致电了我的工作。但是从00:00:00到23:59:59。它看到弹跳并不在乎我设定的时间。
@Component
public class PersianMonthlyJobTrigger implements Trigger {
final Logger logger = Logger.getLogger(this.getClass());
@Override
public Date nextExecutionTime(TriggerContext triggerContext) {
return getTriggerDate();
}
private Integer calculateNextDayOfJob() {
int today = PersianCalendarUtils.getPersianDate();
String nextDayOfJob;
if (PersianCalendarUtils.getDayOfMonth(today) != 1) {//get first day of next month
String month = String.valueOf(PersianCalendarUtils.getMonth(today));
if (!month.equals("12")) {
month = String.valueOf(Integer.valueOf(month) + 1);
month = (month.length() == 2 ? month : "0" + month);
nextDayOfJob = String.valueOf(PersianCalendarUtils.getYear(today) + month + "01");
} else
nextDayOfJob = (PersianCalendarUtils.getYear(today) + 1) + "0101";
} else
nextDayOfJob = String.valueOf(today);
return PersianCalendarUtils.daysBetween(today, Integer.valueOf(nextDayOfJob));
}
private Date getTriggerDate() {
Calendar nextExecutionTime = Calendar.getInstance();
logger.info(nextExecutionTime.getTime());
nextExecutionTime.set(Calendar.HOUR_OF_DAY, 0);
nextExecutionTime.set(Calendar.MINUTE, 1);
nextExecutionTime.set(Calendar.SECOND, 1);
nextExecutionTime.set(Calendar.MILLISECOND, 1);
nextExecutionTime.add(Calendar.DAY_OF_YEAR, calculateNextDayOfJob());
logger.info(nextExecutionTime.getTime());
return nextExecutionTime.getTime();
}
}
设置日历之前我的日志输出:
2018-07-23 12:34:28 INFO ir.co.isc.schedule.PersianMonthlyJobTrigger:51 - Mon Jul 23 12:34:28 IRDT 2018
并设置时间后:
2018-07-23 12:34:28 INFO ir.co.isc.schedule.PersianMonthlyJobTrigger:63 - Mon Jul 23 00:01:01 IRDT 2018
我该如何解决这个问题?我的意思是,在每个假的月份的00:00:01,春季只给我打电话一次。 谢谢你对我的帮助