0

I have an annotated method width @Scheduled with an cron of */15 * * * * ? (run each 15 seconds).

Sometimes this process take more than 15 seconds to run.

Is there any way to avoid the call of the @Scheduled if it's already running?

My workaround currently is a flag field in the class to signal if the process is running, and if it is marked the code exits before execute the main code.

Beto Neto
  • 3,962
  • 7
  • 47
  • 81

1 Answers1

3

I think it's already the case, if the first job has'nt finished, the second will not start.

See : How to prevent overlapping schedules in Spring?

If it isn't working, you can also use an AtomicBoolean to check if you must start the process or not.

Oreste Viron
  • 3,592
  • 3
  • 22
  • 34