hello ,I found an issue.

@Scheduled(cron = "0 0 0 ? * 5#3") is not supported.

I wanted my task to run on the third Thursday of each month, but unfortunately the compiler reported an error. But I checked the cron itself, but the syntax appears to be correct.

My code example is as follows:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

@SpringBootApplication
@EnableScheduling
public class TestScheduledApplication{
    public static void main(String[] args) {
        SpringApplication.run(TestScheduledApplication.class, args);
    }
    @Scheduled(cron = "0 0 0 ? * 5#3")
    public void testScheduled(){
        System.out.println("hello world");
    }
}

My compiler reported an error as follows :

Caused by: java.lang.IllegalStateException: Encountered invalid @Scheduled method 'testScheduled': For input string: "5#3"
    at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.processScheduled(ScheduledAnnotationBeanPostProcessor.java:469) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
    at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.lambda$null$1(ScheduledAnnotationBeanPostProcessor.java:333) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
    at java.lang.Iterable.forEach(Iterable.java:75) ~[na:1.8.0_77]
    at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.lambda$postProcessAfterInitialization$2(ScheduledAnnotationBeanPostProcessor.java:333) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
    at java.util.LinkedHashMap.forEach(LinkedHashMap.java:676) ~[na:1.8.0_77]
    at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.postProcessAfterInitialization(ScheduledAnnotationBeanPostProcessor.java:332) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:437) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1706) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:579) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
    ... 15 common frames omitted

Comment From: suryalokhande

you can refer this -> https://crontab.guru

Comment From: sbrannen

The 5#3 syntax is a custom feature of the Quartz framework:

# - used to specify “the nth” XXX day of the month. For example, the value of 6#3 in the day-of-week field means “the third Friday of the month” (day 6 = Friday and #3 = the 3rd one in the month). Other examples: 2#1 = the first Monday of the month and 4#5 = the fifth Wednesday of the month. Note that if you specify #5 and there is not 5 of the given day-of-week in the month, then no firing will occur that month.

This syntax is not currently supported by org.springframework.scheduling.support.CronSequenceGenerator, but it could theoretically be added.

@snicoll, what are your thoughts on adding support for this syntax?

Comment From: snicoll

I'd prefer to stick with ANSI if at all possible. Adding Quartz or any other scheduling engine specific format makes it harder to document the feature. I am not aware of any custom format our cron parser has but if it has some already, I am not against adding support for this one.

Comment From: sbrannen

I'd prefer to stick with ANSI if at all possible.

AFAIK, it's not an ANSI standard but rather a de facto standard used in Linux and BSD distributions. For example, our implementation is documented as adhering to the syntax defined here for BSD.

Adding Quartz or any other scheduling engine specific format makes it harder to document the feature.

True, though I can imagine that Java developers are often familiar with the syntax supported by Quartz and may expect Spring to support that as well. Of course, that does not mean Spring is obligated to support it.

I am not aware of any custom format our cron parser has but if it has some already, I am not against adding support for this one.

Glancing at the code, it appears that we do not support any custom format, and I assume we would document it if we strayed from the de facto standard.