added try-catch-blocks around CronJob parsing and CronJob handling

This commit is contained in:
kmfdm 2005-08-09 12:55:23 +00:00
parent 5982de3b48
commit 9b97203b3a

View file

@ -1480,71 +1480,80 @@ public final class Application implements IPathElement, Runnable {
} }
} }
if ((cronJobs == null) || (props.lastModified() > lastCronParse)) { try {
updateProperties(); if ((cronJobs == null) || (props.lastModified() > lastCronParse)) {
cronJobs = CronJob.parse(props); updateProperties();
lastCronParse = props.lastModified(); cronJobs = CronJob.parse(props);
lastCronParse = props.lastModified();
}
} catch (Exception ex) {
logEvent ("error parsing CronJobs: " + ex);
ex.printStackTrace();
} }
Date date = new Date(); try {
List jobs = new ArrayList(cronJobs); Date date = new Date();
List jobs = new ArrayList(cronJobs);
jobs.addAll(customCronJobs.values());
CronJob.sort(jobs); jobs.addAll(customCronJobs.values());
CronJob.sort(jobs);
logEvent("Running cron jobs: " + jobs);
if (!activeCronJobs.isEmpty()) { logEvent("Running cron jobs: " + jobs);
logEvent("Cron jobs still running from last minute: " + activeCronJobs); if (!activeCronJobs.isEmpty()) {
} logEvent("Cron jobs still running from last minute: " + activeCronJobs);
}
for (Iterator i = jobs.iterator(); i.hasNext();) {
CronJob job = (CronJob) i.next(); for (Iterator i = jobs.iterator(); i.hasNext();) {
CronJob job = (CronJob) i.next();
if (job.appliesToDate(date)) {
// check if the job is already active ... if (job.appliesToDate(date)) {
if (activeCronJobs.containsKey(job.getName())) { // check if the job is already active ...
logEvent(job + " is still active, skipped in this minute"); if (activeCronJobs.containsKey(job.getName())) {
logEvent(job + " is still active, skipped in this minute");
continue;
}
RequestEvaluator evaluator;
try {
evaluator = getEvaluator();
} catch (RuntimeException rt) {
if (running) {
logEvent("couldn't execute " + job +
", maximum thread count reached");
continue; continue;
} else {
break;
} }
}
RequestEvaluator evaluator;
// if the job has a long timeout or we're already late during this minute
// the job is run from an extra thread
if ((job.getTimeout() > 20000) ||
(CronJob.millisToNextFullMinute() < 30000)) {
CronRunner runner = new CronRunner(evaluator, job);
activeCronJobs.put(job.getName(), runner);
runner.start();
} else {
try { try {
evaluator.invokeInternal(null, job.getFunction(), evaluator = getEvaluator();
new Object[0], job.getTimeout()); } catch (RuntimeException rt) {
} catch (Exception ex) { if (running) {
logEvent("error running " + job + ": " + ex); logEvent("couldn't execute " + job +
} finally { ", maximum thread count reached");
releaseEvaluator(evaluator);
continue;
} else {
break;
}
}
// if the job has a long timeout or we're already late during this minute
// the job is run from an extra thread
if ((job.getTimeout() > 20000) ||
(CronJob.millisToNextFullMinute() < 30000)) {
CronRunner runner = new CronRunner(evaluator, job);
activeCronJobs.put(job.getName(), runner);
runner.start();
} else {
try {
evaluator.invokeInternal(null, job.getFunction(),
new Object[0], job.getTimeout());
} catch (Exception ex) {
logEvent("error running " + job + ": " + ex);
} finally {
releaseEvaluator(evaluator);
}
} }
} }
} }
} catch (Exception ex) {
logEvent("error handling CronJobs: " + ex);
ex.printStackTrace();
} }
long sleepInterval = CronJob.millisToNextFullMinute(); long sleepInterval = CronJob.millisToNextFullMinute();
try { try {
String sleepProp = props.getProperty("schedulerInterval"); String sleepProp = props.getProperty("schedulerInterval");