Last active
August 29, 2015 14:10
-
-
Save jiaozhu/ff4a680ebb3a5c054023 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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