If the question is about can I use mulitple globals in the same thread, yes that is also possible.

Just create another javax.script.Bindings and set it as ENGINE_SCOPE in your ScriptEngine instance. Any future "eval" on that engine will use a fresh 'global' scope object.

Within a script, you can use loadWithNewGlobal function to load a script into a fresh JS global scope object.
See also https://wiki.openjdk.java.net/display/Nashorn/Nashorn+extensions

-Sundar

On Monday 13 October 2014 01:18 PM, Attila Szegedi wrote:
Globals don't have a thread affinity, but they're also not threadsafe (since 
JavaScript as a language isn't). This means that you can have multiple threads 
share one Global, but not concurrently; you'll need to provide synchronization 
around thread access to your Global, to make sure only one thread is using it 
at any given time.

Attila.

On Oct 12, 2014, at 9:07 PM, Serguei Mourachov <[email protected]> wrote:

We have a project where several thousands of script "instances" should be 
called/executed using limited number of threads.
Is it possible to use multiple global objects invoking script functions from 
the same thread?


Reply via email to