0

I am trying to write one cron expression to run it in everyday in midnight (12:00 AM).

@Scheduled(cron = "0 0 0 * * ?")
@Component
@RequiredArgsConstructor
public class TestScheduler {

    private final UserService userService;
    private final TestService testService;

    @Scheduled(cron = "0 0 0 * * ?")
    public void anonymizedApplicant() {
        testService.getUsers().forEach(user -> {
            userService.remove(user.getId());
        });
    }

}

is it correct expression if not, could someone help me to write this.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
keepmoving
  • 1,813
  • 8
  • 34
  • 74
  • Did you try e.g. https://www.freeformatter.com/cron-expression-generator-quartz.html? – jonrsharpe May 10 '20 at 17:37
  • I prepared this expression from there only, but after setting this value. Cron not waiting for 12.A.M and its keeping running. – keepmoving May 10 '20 at 17:39
  • What do you mean *"its keeping running"*? Please give a [mre] and explain the behaviour you're seeing. – jonrsharpe May 10 '20 at 17:43
  • I updated the example with full code and observed behavior cron is running after each min. – keepmoving May 10 '20 at 17:51
  • Does this answer your question? [Spring Scheduling - Cron expression for everyday at midnight not working?](https://stackoverflow.com/questions/45124756/spring-scheduling-cron-expression-for-everyday-at-midnight-not-working) – jonrsharpe May 10 '20 at 17:52
  • Its working fine, I had to restart the application. – keepmoving May 11 '20 at 03:14

0 Answers0