ceki 2004/04/22 13:15:41
Modified: src/java/org/apache/log4j/scheduler Scheduler.java
Log:
The Schduler executes jobs in a safe box in order to isolate itself from
job execution failures.
Revision Changes Path
1.4 +14 -1 logging-log4j/src/java/org/apache/log4j/scheduler/Scheduler.java
Index: Scheduler.java
===================================================================
RCS file:
/home/cvs/logging-log4j/src/java/org/apache/log4j/scheduler/Scheduler.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Scheduler.java 22 Apr 2004 20:02:17 -0000 1.3
+++ Scheduler.java 22 Apr 2004 20:15:41 -0000 1.4
@@ -19,6 +19,8 @@
import java.util.List;
import java.util.Vector;
+import org.apache.log4j.helpers.LogLog;
+
/**
* A simple but still useful implementation of a Scheduler (in memory only).
@@ -161,7 +163,7 @@
ScheduledJobEntry sje = (ScheduledJobEntry) jobList.get(0);
long now = System.currentTimeMillis();
if(now >= sje.desiredExecutionTime) {
- sje.job.execute();
+ executeInABox(sje.job);
jobList.remove(0);
if(sje.period > 0) {
sje.desiredExecutionTime = now + sje.period;
@@ -173,6 +175,17 @@
}
}
System.out.println("Leaving scheduler run method");
+ }
+
+ /**
+ * We do not want a single failure to affect the whole scheduler.
+ */
+ void executeInABox(Job job) {
+ try {
+ job.execute();
+ } catch(Exception e) {
+ LogLog.error("The execution of the job threw an exception", e);
+ }
}
void linger() {
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]