Created
October 10, 2011 14:24
-
-
Save abstractj/1275445 to your computer and use it in GitHub Desktop.
SimpleJob
This file contains hidden or 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.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