0

I have a Spring @scheduled task in my application that will start every 2 minutes. In some situation, the task never comes back so the task will not execute after this.

@Scheduled(fixedDelay = ....)
private void task() {
}

Anyway to set a timeout for the scheduled task to force it end after a certain period of time?

user2777473
  • 3,736
  • 5
  • 26
  • 39

1 Answers1

0

Maybe you want to use fixed rate instead of fixed delay:

@Scheduled(fixedRate = 1000)
private void task() {
}

The beginning of the task execution doesn’t wait for the completion of the previous execution when you use fixed rate. Also consider usage of Future in the internal of your business logic for preventing slow task to hang over long periods.

Lorelorelore
  • 3,335
  • 8
  • 29
  • 40