3

My job is running every at the time specified but its running every second of time specified, for example if I set a job to run at 22:54 it will run every second from 22:54:00 until 22:54:59. I want it to just run once at the time specified...any help is much appreciated

my code:

@Scheduled(cron = "* 54 22 * * ?")
    public void getCompaniess() {
         System.out.println(new Date()+" > Running testScheduledMethod...");

    }

output: Thu Mar 12 22:54:00 GMT 2020 > Running testScheduledMethod... Thu Mar 12 22:54:01 GMT 2020 > Running testScheduledMethod... ..... Thu Mar 12 22:54:59 GMT 2020 > Running testScheduledMethod...

Carl
  • 43
  • 2
  • 7

2 Answers2

3

Change the first * to 0, with a star you are saying "every second".

Replacing it with a 0 (or any other number 0-59) will have it run on that "second" instead of "all of them".

Will Hartung
  • 111,665
  • 19
  • 124
  • 199
  • This worked, I've been pulling my hair our trying to figure out the issue. Thank you – Carl Mar 12 '20 at 23:36
1
@Scheduled(cron = "0 54 22 * * ?")
public void getCompaniess() {
    System.out.println(new Date()+" > Running testScheduledMethod...");
}
Ilya Lysenko
  • 1,641
  • 15
  • 22
  • 1
    Here you can find another samples of schedule: https://stackoverflow.com/questions/26147044/spring-cron-expression-for-every-day-101am – Ilya Lysenko Mar 12 '20 at 23:23