0

is there any expert having the issue using springboot scheduler

trying to set it to run between 2pm til 10pm on weekday every 15mins/per hour, but it seem like trigger by minute, is that because my cron is wrong or i shld do smthg to control it ?

running in linux server via springboot-web-started

@Scheduled(cron = "0 15 14-22 * * MON-FRI")
private void fireDownload() {
    log.info("fireDownload");

    this.jmsXXXX.run(Constants.XXXX);
}

version

spring-boot 2.4.2
java 11

enter image description here

Kim
  • 980
  • 1
  • 15
  • 29
  • If you have the quartz schedular underneath (which should be the default). Please try "0 0/15 14-22 ? * MON-FRI". You cannot set both the day of month and the day of week indicators, which you are. – Gerben Jongerius Jan 21 '21 at 08:01
  • @GerbenJongerius: Tested your suggestion as well, no difference. Please see my updated answer below. – Roar S. Jan 21 '21 at 08:37

1 Answers1

2

Please try this

@Scheduled(cron = "0 */15 14-22 * * MON-FRI")

You say in a comment that this is not working, so let's test this with a simple proof-of-concept that fires every 5 minute

@Scheduled(cron = "0 */5 8-22 * * MON-FRI")
private void cronPOC() {
    log.info("cronPOC triggered by cron");
}

Screen-shot below shows that the POC is indeed working.

enter image description here

While we're at testing, let's put @GerbenJongerius suggestion from comment above to the test as well (with some tiny changes in order to speed things up).

@Scheduled(cron = "0 0/5 8-22 ? * MON-FRI")
private void cronPOC() {
    log.info("cronPOC triggered by cron v2");
}

... and this is also working enter image description here

Some Spring cron examples with explanations here: https://stackoverflow.com/a/26147143/14072498

Roar S.
  • 8,103
  • 1
  • 15
  • 37
  • thanks, i tried the example u share and also read the link u share, there is not helpful for my case as job keep trigger every minutes not same as the setting 0/15 or */15 or 15 – Kim Jan 21 '21 at 07:37
  • @Kim: Please see my updated answer with a proof-of-concept. Please try the same at your side. BR – Roar S. Jan 21 '21 at 08:02
  • ok great, i found my problem that not because of the cron, that happen when schedule method is create in another class which is not in Springboot application main class.... when i compare this both, it happen 6 times duplicated running in my component class but the schedule method in main class which just work fine – Kim Jan 21 '21 at 16:03
  • @Kim: Good to hear that you found the error, I suspected something like this. Please close the issue by accepting my answer. BR – Roar S. Jan 21 '21 at 20:07