1 17 18 package org.quartz.examples.example4; 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.JobDataMap; 25 import org.quartz.JobExecutionContext; 26 import org.quartz.JobExecutionException; 27 import org.quartz.StatefulJob; 28 29 37 public class ColorJob implements StatefulJob { 38 39 private static Log _log = LogFactory.getLog(ColorJob.class); 40 41 public static final String FAVORITE_COLOR = "favorite color"; 43 public static final String EXECUTION_COUNT = "count"; 44 45 private int _counter = 1; 49 50 59 public ColorJob() { 60 } 61 62 72 public void execute(JobExecutionContext context) 73 throws JobExecutionException { 74 75 String jobName = context.getJobDetail().getFullName(); 78 79 JobDataMap data = context.getJobDetail().getJobDataMap(); 81 String favoriteColor = data.getString(FAVORITE_COLOR); 82 int count = data.getInt(EXECUTION_COUNT); 83 _log.info("ColorJob: " + jobName + " executing at " + new Date () + "\n" + 84 " favorite color is " + favoriteColor + "\n" + 85 " execution count (from job map) is " + count + "\n" + 86 " execution count (from job member variable) is " + _counter); 87 88 count++; 91 data.put(EXECUTION_COUNT, count); 92 93 _counter++; 97 } 98 99 } | Popular Tags |