Skip to content

Instantly share code, notes, and snippets.

@jiaozhu
Last active August 29, 2015 14:10
Show Gist options
  • Save jiaozhu/ff4a680ebb3a5c054023 to your computer and use it in GitHub Desktop.
Save jiaozhu/ff4a680ebb3a5c054023 to your computer and use it in GitHub Desktop.
package com.blogspot.alotacode.scheduler;
import java.util.List;
import org.apache.log4j.Logger;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.SchedulerException;
import org.springframework.scheduling.quartz.QuartzJobBean;
/**
* @author Timothy Mugayi
*/
public abstract class QuartzJob<T> extends QuartzJobBean {
private static final Logger log = Logger.getLogger(QuartzJob.class);
@SuppressWarnings("unchecked")
@Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
try {
List<JobExecutionContext> jobs = context.getScheduler().getCurrentlyExecutingJobs();
if (jobs != null && !jobs.isEmpty()) {
for (JobExecutionContext job : jobs) {
if (job.getTrigger().equals(context.getTrigger()) && !job.getJobInstance().equals(this)) {
log.info("There's another instance running, : " + this);
return;
}
}
}
} catch (SchedulerException e) {
log.error(e.getCause());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment