Reputation: 4102
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.
Upvotes: 0
Views: 5279
Reputation: 3805
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.
Upvotes: 3