Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cron expression to trigger on 25 of every month

Tags:

java

spring

cron

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)
like image 911
elle Avatar asked May 21 '11 10:05

elle


1 Answers

@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

like image 136
Sean Patrick Floyd Avatar answered Sep 22 '22 10:09

Sean Patrick Floyd