Skip to content

Instantly share code, notes, and snippets.

@abstractj
Created October 11, 2011 02:18
Show Gist options
  • Save abstractj/1277112 to your computer and use it in GitHub Desktop.
Save abstractj/1277112 to your computer and use it in GitHub Desktop.
WatchDogSchedulerFactory
package com.abstractj.jobs;
import org.quartz.*;
/**
* User: Bruno
* Date: 10/10/11
* Time: 10:17 PM
*/
public class WatchDogJob implements Job {
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
try {
jobExecutionContext.getScheduler().interrupt("interruptableJob1", "group1");
} catch (Exception e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
}
package com.abstractj.scheduler;
import com.abstractj.jobs.SimpleJob;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date;
/**
* User: Bruno
* Date: 10/5/11
* Time: 8:52 PM
*/
public class WatchDogSchedulerFactory {
private static final Logger LOGGER = LoggerFactory.getLogger(WatchDogSchedulerFactory.class);
private static SchedulerFactory sf = new StdSchedulerFactory();
private static Scheduler scheduler;
public static void createScheduler() throws SchedulerException, Exception {
scheduler = sf.getScheduler();
try {
JobDetail jobDetail = new JobDetail("interruptableJob1", "group1", SimpleJob.class);
SimpleTrigger trigger = new SimpleTrigger("trigger1", "group1", new Date(), null, SimpleTrigger.REPEAT_INDEFINITELY, 5L);
scheduler.scheduleJob(jobDetail, trigger);
JobDetail watchDogJob = new JobDetail("watchDogJob", "watchGroup", WatchDogSchedulerFactory.WatchDogJob.class);
SimpleTrigger trigger2 = new SimpleTrigger("watchDogTrigger", "watchDogGroup", new Date(), null, SimpleTrigger.REPEAT_INDEFINITELY, 2L);
scheduler.scheduleJob(watchDogJob, trigger2);
scheduler.start();
} catch (Exception ex) {
LOGGER.error("Parser error", ex);
}
}
class WatchDogJob implements Job {
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
try {
jobExecutionContext.getScheduler().interrupt("interruptableJob1", "group1");
} catch (Exception e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment