added try-catch-blocks around CronJob parsing and CronJob handling
This commit is contained in:
parent
5982de3b48
commit
9b97203b3a
1 changed files with 64 additions and 55 deletions
|
@ -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());
|
jobs.addAll(customCronJobs.values());
|
||||||
CronJob.sort(jobs);
|
CronJob.sort(jobs);
|
||||||
|
|
||||||
logEvent("Running cron jobs: " + jobs);
|
logEvent("Running cron jobs: " + jobs);
|
||||||
if (!activeCronJobs.isEmpty()) {
|
if (!activeCronJobs.isEmpty()) {
|
||||||
logEvent("Cron jobs still running from last minute: " + activeCronJobs);
|
logEvent("Cron jobs still running from last minute: " + activeCronJobs);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Iterator i = jobs.iterator(); i.hasNext();) {
|
for (Iterator i = jobs.iterator(); i.hasNext();) {
|
||||||
CronJob job = (CronJob) i.next();
|
CronJob job = (CronJob) i.next();
|
||||||
|
|
||||||
if (job.appliesToDate(date)) {
|
if (job.appliesToDate(date)) {
|
||||||
// check if the job is already active ...
|
// check if the job is already active ...
|
||||||
if (activeCronJobs.containsKey(job.getName())) {
|
if (activeCronJobs.containsKey(job.getName())) {
|
||||||
logEvent(job + " is still active, skipped in this minute");
|
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;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// if the job has a long timeout or we're already late during this minute
|
RequestEvaluator evaluator;
|
||||||
// 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");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue