org.quartz.examples.example7
public class: DumbInterruptableJob [javadoc |
source]
java.lang.Object
org.quartz.examples.example7.DumbInterruptableJob
All Implemented Interfaces:
InterruptableJob
A dumb implementation of an InterruptableJob, for unittesting purposes.
- author:
< - a href="mailto:bonhamcm@thirdeyeconsulting.com">Chris Bonham
- author:
Bill - Kratzer
| Method from org.quartz.examples.example7.DumbInterruptableJob Summary: |
|---|
|
execute, interrupt |
| Method from org.quartz.examples.example7.DumbInterruptableJob Detail: |
public void execute(JobExecutionContext context) throws JobExecutionException {
_jobName = context.getJobDetail().getFullName();
_log.info("---- " + _jobName + " executing at " + new Date());
try {
// main job loop... see the JavaDOC for InterruptableJob for discussion...
// do some work... in this example we are 'simulating' work by sleeping... :)
for (int i = 0; i < 4; i++) {
try {
Thread.sleep(1000L);
} catch (Exception ignore) {
ignore.printStackTrace();
}
// periodically check if we've been interrupted...
if(_interrupted) {
_log.info("--- " + _jobName + " -- Interrupted... bailing out!");
return; // could also choose to throw a JobExecutionException
// if that made for sense based on the particular
// job's responsibilities/behaviors
}
}
} finally {
_log.info("---- " + _jobName + " completed at " + new Date());
}
}
|
public void interrupt() throws UnableToInterruptJobException {
_log.info("---" + " -- INTERRUPTING --");
_interrupted = true;
}
|