如何编写cron表达式以在每个月的25日在早上9点开始触发一个函数?
当我执行此代码时,
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; @Service public class PayrollSchedulerImpl implements PayrollScheduler{ @Scheduled(cron="0 9 25 1 * ?") public void calculateSalaryScheduled() { calculateSalary(); } public void calculateSalary() { /* */ } }
我收到错误,
java.lang.StackOverflowError sun.util.calendar.ZoneInfo.getOffsets(Unknown Source) sun.util.calendar.ZoneInfo.getOffsets(Unknown Source) java.util.GregorianCalendar.computeFields(Unknown Source) java.util.GregorianCalendar.computeTime(Unknown Source) java.util.Calendar.updateTime(Unknown Source) java.util.Calendar.complete(Unknown Source) java.util.Calendar.get(Unknown Source) org.springframework.scheduling.support.CronSequenceGenerator.doNext(CronSequenceGenerator.java:130)
解决方法
@Scheduled(cron="0 9 25 1 * ?")
这只是1月1日,时间无效,你需要这个:
@Scheduled(cron="0 0 9 25 * ?")