Cannot run more than 10 runScriptlets in a JVM using JRuby embed
I create 16 ScriptingContainer() instances as follows...
private void initScriptContainer() {
scriptLog = new PrintWriter(new ScriptEngineWriter(scriptOutput), true);
scriptContainer = new ScriptingContainer(LocalContextScope.SINGLETHREAD);
scriptContainer.setWriter(scriptLog);
scriptContainer.setErrorWriter(scriptLog);
scriptContainer.runScriptlet("puts 'ruby scripting engine started...'");
dsl = new AppDSL(this, tstRsltLog);
scriptContainer.put("$ratt", dsl);
scriptContainer.setAttribute(AttributeName.BASE_DIR, RattApp.getScriptsDir());
Object receiver = scriptContainer.runScriptlet(PathType.RELATIVE, "../Resources/ratt.dsl");
}
Each of these instances writes its output to a JTextArea via the ScriptEngineWriter class (my own class) and associates a domain specific language in the variable map. In each one of these instances a JRuby runScriptlet() method can be run executed in a SwingWorker class as such..
ScriptExecutionWorker() {
String script = scriptTextArea.getText();
testscript = new StringBuilder("RattDSL.doScript { " + script + "}");
}
@Override
protected Void doInBackground() {
scriptOutput.setText("");
scriptExecutionStatusValue.setText("Running");
if (StringUtils.isNotBlank(testRunTxtFld.getText())) {
if (!tstRsltLog.openTestRun(testRunTxtFld.getText())) {
return null;
}
}
setTestsPassed(0);
setTestsFailed(0);
dsl.clearTSTagName();
tstRsltLog.setScriptFile(getScriptFile().getName());
try {
for (int i = 1, j = 1; i <= scriptIterations; i+, j+) {
setScriptLoopCnt(j);
tstRsltLog.setIterationCnt(j);
if (scriptCancelled) {
log.info("script processing is now cancelled");
break;
}
scriptIsRunning = true;
scriptContainer.runScriptlet(testscript.toString());
if (i == INFINITE_ITERATIONS) {
i--; // keep it going forever
}
}
} catch (Exception e) {
log.error("script execution error: ", e);
}
log.info("exiting script worker doInBackground");
return null;
}
Everything runs perfectly until I get to the 11th SwingExecutionWorker thread, the code blocks on the runScriptlet() method. It stays blocked until the number of simultaneously runScriptlet()'s dips below 10, at which point, the currently blocked runScriptlet() begins executing. I cannot get the number of simultaneously runScriptlet()'s to exceed 10. I was hoping there would be a config parameter I could set to change this limit but there appears to be none. I tried -Djruby.runtime.max=16 as a java command line parameter but it did not change anything.
Can an option or property be added to allow this limit to go above 10.
|