1 package org.apache.turbine.services.schedule; 2 3 18 19 import org.apache.commons.logging.Log; 20 import org.apache.commons.logging.LogFactory; 21 import org.apache.turbine.modules.ScheduledJobLoader; 22 23 32 public class WorkerThread 33 implements Runnable 34 { 35 38 private JobEntry je = null; 39 40 41 private static Log log = LogFactory.getLog(ScheduleService.LOGGER_NAME); 42 43 48 public WorkerThread(JobEntry je) 49 { 50 this.je = je; 51 } 52 53 56 public void run() 57 { 58 if (je == null || je.isActive()) 59 { 60 return; 61 } 62 63 try 64 { 65 if (!je.isActive()) 66 { 67 je.setActive(true); 68 logStateChange("started"); 69 ScheduledJobLoader.getInstance().exec(je, je.getTask()); 70 } 71 } 72 catch (Exception e) 73 { 74 log.error("Error in WorkerThread for scheduled job #" + 75 je.getPrimaryKey() + ", task: " + je.getTask(), e); 76 } 77 finally 78 { 79 if (je.isActive()) 80 { 81 je.setActive(false); 82 logStateChange("completed"); 83 } 84 } 85 } 86 87 92 private final void logStateChange(String state) 93 { 94 log.debug("Scheduled job #" + je.getPrimaryKey() + ' ' + state + 95 ", task: " + je.getTask()); 96 } 97 } 98 | Popular Tags |