1 17 18 package org.quartz.examples.example5; 19 20 import java.util.Date ; 21 22 import org.quartz.StatefulJob; 23 import org.quartz.JobDataMap; 24 import org.quartz.JobExecutionContext; 25 import org.quartz.JobExecutionException; 26 27 34 public class StatefulDumbJob implements StatefulJob { 35 36 43 44 public static final String NUM_EXECUTIONS = "NumExecutions"; 45 46 public static final String EXECUTION_DELAY = "ExecutionDelay"; 47 48 55 56 public StatefulDumbJob() { 57 } 58 59 66 67 76 public void execute(JobExecutionContext context) 77 throws JobExecutionException { 78 System.err.println("---" + context.getJobDetail().getFullName() 79 + " executing.[" + new Date () + "]"); 80 81 JobDataMap map = context.getJobDetail().getJobDataMap(); 82 83 int executeCount = 0; 84 if (map.containsKey(NUM_EXECUTIONS)) { 85 executeCount = map.getInt(NUM_EXECUTIONS); 86 } 87 88 executeCount++; 89 90 map.put(NUM_EXECUTIONS, executeCount); 91 92 long delay = 5000l; 93 if (map.containsKey(EXECUTION_DELAY)) { 94 delay = map.getLong(EXECUTION_DELAY); 95 } 96 97 try { 98 Thread.sleep(delay); 99 } catch (Exception ignore) { 100 } 101 102 System.err.println(" -" + context.getJobDetail().getFullName() 103 + " complete (" + executeCount + ")."); 104 105 } 106 107 } | Popular Tags |