* Catch Linkage- and VirtualMachineErrors in scheduler loops in order to

keep on trucking in the face of OutOfMemoryErrors and the like.
* Sleep first, then do the work in scheduler loop.
This commit is contained in:
hns 2007-05-03 14:51:37 +00:00
parent 72db2bf08e
commit 657b86dee5

View file

@ -1452,42 +1452,51 @@ public final class Application implements Runnable {
// interval between session cleanups // interval between session cleanups
long lastSessionCleanup = System.currentTimeMillis(); long lastSessionCleanup = System.currentTimeMillis();
// logEvent ("Starting scheduler for "+name);
while (Thread.currentThread() == worker) { while (Thread.currentThread() == worker) {
// purge sessions
try { try {
lastSessionCleanup = cleanupSessions(lastSessionCleanup); // interval between scheduler runs
} catch (Exception x) { long sleepInterval = 60000;
logError("Error in session cleanup", x);
}
// execute cron jobs try {
try { String sleepProp = props.getProperty("schedulerInterval");
executeCronJobs(); if (sleepProp != null) {
} catch (Exception x) { sleepInterval = Math.max(1000, Integer.parseInt(sleepProp) * 1000);
logError("Error in cron job execution", x); } else {
} sleepInterval = CronJob.millisToNextFullMinute();
}
long sleepInterval = 60000; } catch (Exception ignore) {
try { // we'll use the default interval
String sleepProp = props.getProperty("schedulerInterval");
if (sleepProp != null) {
sleepInterval = Math.max(1000, Integer.parseInt(sleepProp) * 1000);
} else {
sleepInterval = CronJob.millisToNextFullMinute();
} }
} catch (Exception ignore) {
// we'll use the default interval
}
// sleep until the next full minute // sleep until the next full minute
try { try {
Thread.sleep(sleepInterval); Thread.sleep(sleepInterval);
} catch (InterruptedException x) { } catch (InterruptedException x) {
worker = null; worker = null;
break; break;
}
// purge sessions
try {
lastSessionCleanup = cleanupSessions(lastSessionCleanup);
} catch (Exception x) {
logError("Error in session cleanup: " + x, x);
} catch (LinkageError x) {
logError("Error in session cleanup: " + x, x);
}
// execute cron jobs
try {
executeCronJobs();
} catch (Exception x) {
logError("Error in cron job execution: " + x, x);
} catch (LinkageError x) {
logError("Error in cron job execution: " + x, x);
}
} catch (VirtualMachineError error) {
logError("Error in scheduler loop: " + error, error);
} }
} }