binding issues

Andreas Mueller am at
Wed Jan 11 17:39:52 UTC 2017


it seems I have a problem understanding Nashorn’s bindings...

I have multiple scripts, each independent of each other. They should run concurrently with their own context and engine scope bindings. This is created as follows for each script:

ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName((String) entity.getProperty("script-language").getValue());
if (engine == null)
    throw new Exception("Engine for script-language '" + entity.getProperty("script-language").getValue() + "' not found!");
ScriptContext newContext = new SimpleScriptContext();
streamContext.engineScope = newContext.getBindings(ScriptContext.ENGINE_SCOPE);

Internally we have a Java-based processor which calls Javascript functions (callbacks). It is always the same thread.

It works fine when I start a script the first time. If I stop it (without stopping the JVM) and restart it (it runs through the code above) or if I run another script concurrently, I’m getting problems in so far that calls inside a Javascript callback to Java objects that set data don’t work. The data is not null on the Javascript callback but null inside the Java method. 

Here is an example callback:

stream.create().memoryGroup("queues", "name").onCreate(function (memoryGroup, key) {
    print("Add:"+ key+"="+stream.memory(key));

The above “stream.create().memory(key)” is a Java method that has a printout:

AddMem: orderpos, mem=HeapMemory{name='orderpos’}

But when I retrieve it with "stream.memory(key)” in the print statement of the Javascript function I’m getting:


For me this points to the bindings, e.g. a binding from a previous running instance of the script or something else. Can somebody provide some help? What do I need to do to have always a clean instance of a binding when I rerun a script without stopping the JVM?


Andreas Mueller
IIT Software GmbH

IIT Software GmbH
Münsterstr. 111, 48145 Münster, Germany
Phone: +49 (0)2506 3049340
Managing Director: Andreas Müller
District Court: Amtsgericht Münster, HRB 16294
VAT-No: DE199945912

This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.

More information about the nashorn-dev mailing list