Skip to content

Instantly share code, notes, and snippets.

@abstractj
Created October 10, 2011 14:24
Show Gist options
  • Save abstractj/1275445 to your computer and use it in GitHub Desktop.
Save abstractj/1275445 to your computer and use it in GitHub Desktop.
SimpleJob
package com.abstractj.jobs;
import org.quartz.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Calendar;
/**
* User: Bruno
* Date: 10/5/11
* Time: 3:04 PM
*/
public class SimpleJob implements Job, InterruptableJob {
private static final Logger LOGGER = LoggerFactory.getLogger(SimpleJob.class);
public void execute(JobExecutionContext context) throws JobExecutionException {
LOGGER.info("Started Job Execution at " + Calendar.getInstance().getTime());
try {
watchDog(context.getScheduler(), context.getJobDetail());
Thread.sleep(1000000000L);
} catch (InterruptedException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} catch (UnableToInterruptJobException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
LOGGER.info("Finished Job Execution at " + Calendar.getInstance().getTime());
}
public void interrupt() throws UnableToInterruptJobException {
LOGGER.error("Job Interrompido");
}
public void watchDog(Scheduler scheduler, JobDetail jobDetail) throws UnableToInterruptJobException, InterruptedException {
long timeout = (Long) jobDetail.getJobDataMap().get("timeout");
Thread.sleep(timeout);
scheduler.interrupt(jobDetail.getName(), jobDetail.getGroup());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment