If no evaluator is available in getEvaluator() and a new one can't be allocated, try waiting a few seconds several times before throwing a max thread count exception.
This commit is contained in:
parent
7cea5ece31
commit
c591ab2e7d
1 changed files with 23 additions and 7 deletions
|
@ -253,6 +253,7 @@ public final class Application implements IPathElement, Runnable {
|
||||||
} catch (Exception ignore) {}
|
} catch (Exception ignore) {}
|
||||||
for (int i=0; i<minThreads; i++) {
|
for (int i=0; i<minThreads; i++) {
|
||||||
RequestEvaluator ev = new RequestEvaluator (this);
|
RequestEvaluator ev = new RequestEvaluator (this);
|
||||||
|
ev.initScriptingEngine ();
|
||||||
freeThreads.push (ev);
|
freeThreads.push (ev);
|
||||||
allThreads.addElement (ev);
|
allThreads.addElement (ev);
|
||||||
}
|
}
|
||||||
|
@ -350,16 +351,18 @@ public final class Application implements IPathElement, Runnable {
|
||||||
protected RequestEvaluator getEvaluator () {
|
protected RequestEvaluator getEvaluator () {
|
||||||
if (stopped)
|
if (stopped)
|
||||||
throw new ApplicationStoppedException ();
|
throw new ApplicationStoppedException ();
|
||||||
|
// first try
|
||||||
try {
|
try {
|
||||||
return (RequestEvaluator) freeThreads.pop ();
|
return (RequestEvaluator) freeThreads.pop ();
|
||||||
} catch (EmptyStackException nothreads) {
|
} catch (EmptyStackException nothreads) {
|
||||||
synchronized (this) {
|
|
||||||
int maxThreads = 12;
|
int maxThreads = 12;
|
||||||
try {
|
try {
|
||||||
maxThreads = Integer.parseInt (props.getProperty ("maxThreads"));
|
maxThreads = Integer.parseInt (props.getProperty ("maxThreads"));
|
||||||
} catch (Exception ignore) {
|
} catch (Exception ignore) {
|
||||||
// property not set, use default value
|
// property not set, use default value
|
||||||
}
|
}
|
||||||
|
synchronized (this) {
|
||||||
|
// allocate a new evaluator
|
||||||
if (allThreads.size() < maxThreads) {
|
if (allThreads.size() < maxThreads) {
|
||||||
logEvent ("Starting evaluator "+(allThreads.size()+1) +" for application "+name);
|
logEvent ("Starting evaluator "+(allThreads.size()+1) +" for application "+name);
|
||||||
RequestEvaluator ev = new RequestEvaluator (this);
|
RequestEvaluator ev = new RequestEvaluator (this);
|
||||||
|
@ -367,8 +370,21 @@ public final class Application implements IPathElement, Runnable {
|
||||||
return (ev);
|
return (ev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new RuntimeException ("Maximum Thread count reached.");
|
|
||||||
}
|
}
|
||||||
|
// we can't create a new evaluator, so we wait if one becomes available.
|
||||||
|
// give it 3 more tries, waiting 3 seconds each time.
|
||||||
|
for (int i=0; i<4; i++) {
|
||||||
|
try {
|
||||||
|
Thread.currentThread().sleep(3000);
|
||||||
|
return (RequestEvaluator) freeThreads.pop ();
|
||||||
|
} catch (EmptyStackException nothreads) {
|
||||||
|
// do nothing
|
||||||
|
} catch (InterruptedException inter) {
|
||||||
|
throw new RuntimeException ("Thread interrupted.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// no luck, give up.
|
||||||
|
throw new RuntimeException ("Maximum Thread count reached.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue