1 17 18 package org.quartz.examples.example7; 19 20 import java.util.Date ; 21 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 import org.quartz.InterruptableJob; 25 import org.quartz.JobExecutionContext; 26 import org.quartz.JobExecutionException; 27 import org.quartz.UnableToInterruptJobException; 28 29 30 38 public class DumbInterruptableJob implements InterruptableJob { 39 40 private static Log _log = LogFactory.getLog(DumbInterruptableJob.class); 42 43 private boolean _interrupted = false; 45 46 private String _jobName = ""; 48 49 54 public DumbInterruptableJob() { 55 } 56 57 58 67 public void execute(JobExecutionContext context) 68 throws JobExecutionException { 69 70 _jobName = context.getJobDetail().getFullName(); 71 _log.info("---- " + _jobName + " executing at " + new Date ()); 72 73 try { 74 77 for (int i = 0; i < 4; i++) { 78 try { 79 Thread.sleep(1000L); 80 } catch (Exception ignore) { 81 ignore.printStackTrace(); 82 } 83 84 if(_interrupted) { 86 _log.info("--- " + _jobName + " -- Interrupted... bailing out!"); 87 return; } 91 } 92 93 } finally { 94 _log.info("---- " + _jobName + " completed at " + new Date ()); 95 } 96 } 97 98 108 public void interrupt() throws UnableToInterruptJobException { 109 _log.info("---" + " -- INTERRUPTING --"); 110 _interrupted = true; 111 } 112 113 } | Popular Tags |