1

I have a simple Spring Boot app that handles some REST API calls and so on. I added @EnableScheduling to my main class and then proceeded to add @Scheduled on top of each function I need to schedule and then added a cron expression.

Spring boot Version : 2.7.1

What I have is the following:

I have three classes. Each class contains a void function scheduled.

I ran the app and everything seems working fine. All the API calls ran smoothly and as excepted, and then I ran the same app but from a jar file using the cmd. The scheduler works fine the first day and then suddenly stops working and then starts working again the day after.

I was monitoring the logs and it turned out that 4 out of 5 days the scheduler ran as expected, but skipped one day for no reason.

Any one might experienced this weird behavior?

main class:

@EnableScheduling
@SpringBootApplication
public class MYCLASSHERE {

    public static void main(String[] args) {
        SpringApplication.run(MYCLASSHERE.class, args);
    }
}

each class has the following structure:

@Service
public class MYOTHERCLASS{
@Scheduled(cron = "0 5 12 * * *")
    public void FUNCTION() {}
}
@Service
public class MYOTHERCLASS{
@Scheduled(cron = "0 10 12 * * *")
    public void FUNCTION() {}
}
@Service
public class MYOTHERCLASS{
@Scheduled(cron = "0 15 12 * * *")
    public void FUNCTION() {}
}

Note that everything is working fine. The scheduler stoppage that I'm experiencing is the only problem when running from a jar file.

1 Answers1

1

try @Scheduled(cron = "0 35,40 14 * * ?") for your function

  • thanks for your comment but is it going to affect the scheduler Not working problem because as it is it's working fine so don't know what "?" in the year value would change and i updated the time values just to be accurate – Mhamad jawad al hajjar Jul 14 '22 at 09:36
  • An explanation of why this would solve the problem would be helpful. – Mark Rotteveel Jul 14 '22 at 12:22