diff --git a/src/helma/framework/core/Application.java b/src/helma/framework/core/Application.java index bc071d54..9c653844 100644 --- a/src/helma/framework/core/Application.java +++ b/src/helma/framework/core/Application.java @@ -77,12 +77,6 @@ public final class Application implements IPathElement, Runnable { */ protected SkinManager skinmgr; - /** - * Each application has one internal request evaluator for calling - * the scheduler and other internal functions. - */ - RequestEvaluator eval; - /** * Collections for evaluator thread pooling */ @@ -283,24 +277,25 @@ public final class Application implements IPathElement, Runnable { loadSessionData(null); } + // create and init type mananger typemgr = new TypeManager(this); typemgr.createPrototypes(); - // logEvent ("Started type manager for "+name); - // eval = new RequestEvaluator (this); - logEvent("Starting evaluators for " + name); + // create and init evaluator/thread lists freeThreads = new Stack(); allThreads = new Vector(); - // allThreads.addElement (eval); // preallocate minThreads request evaluators int minThreads = 0; try { minThreads = Integer.parseInt(props.getProperty("minThreads")); } catch (Exception ignore) { + // not parsable as number, keep 0 } + logEvent("Starting "+minThreads+" evaluator(s) for " + name); + for (int i = 0; i < minThreads; i++) { RequestEvaluator ev = new RequestEvaluator(this); @@ -339,7 +334,7 @@ public final class Application implements IPathElement, Runnable { public void start() { starttime = System.currentTimeMillis(); worker = new Thread(this, "Worker-" + name); - worker.setPriority(Thread.NORM_PRIORITY + 2); + // worker.setPriority(Thread.NORM_PRIORITY + 2); worker.start(); // logEvent ("session cleanup and scheduler thread started"); @@ -1108,17 +1103,7 @@ public final class Application implements IPathElement, Runnable { * by an active RequestEvaluator thread. */ private Object invokeFunction(Object obj, String func, Object[] args) { - Thread thread = Thread.currentThread(); - RequestEvaluator reval = null; - int l = allThreads.size(); - - for (int i = 0; i < l; i++) { - RequestEvaluator r = (RequestEvaluator) allThreads.get(i); - - if ((r != null) && (r.rtx == thread)) { - reval = r; - } - } + RequestEvaluator reval = getCurrentRequestEvaluator(); if (reval != null) { try { @@ -1233,7 +1218,7 @@ public final class Application implements IPathElement, Runnable { // the first time an url like /appname/api/ is parsed, the application is read again // parsed for comments and exposed as an IPathElement if (name.equals("api")) { - return eval.scriptingEngine.getIntrospector(); + return getCurrentRequestEvaluator().scriptingEngine.getIntrospector(); } return null; @@ -1319,18 +1304,21 @@ public final class Application implements IPathElement, Runnable { long lastCleanup = System.currentTimeMillis(); // logEvent ("Starting scheduler for "+name); - // as first thing, invoke function onStart in the root object - eval = new RequestEvaluator(this); - allThreads.addElement(eval); // read in standard prototypes to make first request go faster typemgr.updatePrototype("root"); typemgr.updatePrototype("global"); + // as first thing, invoke function onStart in the root object + RequestEvaluator eval = getEvaluator(); try { eval.invokeFunction((INode) null, "onStart", new Object[0]); } catch (Exception ignore) { logEvent("Error in " + name + "/onStart(): " + ignore); + } finally { + if (!stopped) { + releaseEvaluator(eval); + } } while (Thread.currentThread() == worker) { @@ -1405,7 +1393,7 @@ public final class Application implements IPathElement, Runnable { try { thisEvaluator = getEvaluator(); } catch (RuntimeException rt) { - if (stopped == false) { + if (!stopped) { logEvent("couldn't execute " + j + ", maximum thread count reached"); @@ -1421,8 +1409,8 @@ public final class Application implements IPathElement, Runnable { (CronJob.millisToNextFullMinute() < 30000)) { CronRunner r = new CronRunner(thisEvaluator, j); - r.start(); activeCronJobs.put(j.getName(), r); + r.start(); } else { try { thisEvaluator.invokeFunction((INode) null, j.getFunction(), @@ -1430,7 +1418,7 @@ public final class Application implements IPathElement, Runnable { } catch (Exception ex) { logEvent("error running " + j + ": " + ex.toString()); } finally { - if (stopped == false) { + if (!stopped) { releaseEvaluator(thisEvaluator); } } @@ -1845,14 +1833,14 @@ public final class Application implements IPathElement, Runnable { thisEvaluator.invokeFunction((INode) null, job.getFunction(), new Object[0], job.getTimeout()); } catch (Exception ex) { + // gets logged in RequestEvaluator + } finally { + if (!stopped) { + releaseEvaluator(thisEvaluator); + } + thisEvaluator = null; + activeCronJobs.remove(job.getName()); } - - if (stopped == false) { - releaseEvaluator(thisEvaluator); - } - - thisEvaluator = null; - activeCronJobs.remove(job.getName()); } } }