quarkusquartz

how to prevent quartz from running another job if the previous one is still running?


I'm using Quarkus. My Quartz jobs are scheduled to run every 10 seconds:

        return TriggerBuilder.newTrigger()
                .withIdentity("my-job")
                .startNow() 
                .withSchedule(
                        SimpleScheduleBuilder.simpleSchedule()
                                .withIntervalInSeconds(10)
                                .repeatForever()
                ).build();

This works fine but jobs keep triggering every 10 seconds irrespective of whether or not the last one finishes. I need the next job to start only if there are no jobs currently running job. How do I accomplish this?


Solution

  • Add @DisallowConcurrentExecution on you Job class.

    as example :

    @DisallowConcurrentExecution
    public class MyScheduledJob implements Job {
     //execution method
    }