java 每月 25 日触发的 Cron 表达式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6081185/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 14:14:44  来源:igfitidea点击:

Cron expression to trigger on 25 of every month

javaspringcron

提问by elle

How to write cron expression to trigger a function on 25th of every month at 9 A.M in the morning?

如何编写cron表达式在每个月的25日早上9点触发一个函数?

When I execute this code,

当我执行这段代码时,

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()
    {
        /* */
    }
}

I get the error,

我得到错误,

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)

回答by Sean Patrick Floyd

@Scheduled(cron="0 9 25 1 * ?")

This is on January 1st only, and the time is invalid, you'll want this instead:

这只是在 1 月 1 日,时间无效,你会想要这个:

@Scheduled(cron="0 0 9 25 * ?")

Reference:CronSequenceGenerator

参考:CronSequenceGenerator