Skip to content

Instantly share code, notes, and snippets.

@jatin-lab49
Created November 24, 2020 19:27
Show Gist options
  • Save jatin-lab49/f730eb9b35a5a752fe05d462f22c7224 to your computer and use it in GitHub Desktop.
Save jatin-lab49/f730eb9b35a5a752fe05d462f22c7224 to your computer and use it in GitHub Desktop.
TIL-Lab49/Ensuring only one Quartz scheduled job runs at one time

With the advances in Lambda and ECS task scheduling, I have not needed to use the trusty Quartz library for the past few years. I recently had to use it though in a project, and realized that the next job was starting when the current job was still running.

Thankfully with Spring, Quartz 2 makes this really easy. Just add the @DisallowConcurrentExecution to your job.

package com.lab49.example;

import org.quartz.DisallowConcurrentExecution;
import org.quartz.job;
import org.quartz.job.JobExecutionContext;

@DisallowConcurrentExecution 
public class TestJob implements Job {

  @Override
  public void execute(JobExecutionContext context) {
    // job logic here
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment