Issue
How to write cron expression to trigger a function on 25th of every month at 9 A.M in the morning?
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)
Solution
@Scheduled(cron="0 9 25 1 * ?")
This is on January 1st only, and the time is invalid, you'll want this instead:
@Scheduled(cron="0 0 9 25 * ?")
Reference: CronSequenceGenerator
Answered By - Sean Patrick Floyd Answer Checked By - Cary Denson (WPSolving Admin)