Beto Neto
Beto Neto

Reputation: 4102

Spring @Scheduled, how to run once at time (not concurrently)

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

Answers (1)

Oreste Viron
Oreste Viron

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

Related Questions