Loss of engine scope in a new Thread

Koray burakkoray at gmail.com
Fri Jan 5 06:37:57 UTC 2018


Hello,

I have a structure which creates a new thread for each client that is
connected and assigns a new ScriptContext to them along with a new
SimpleBinding for engine scope and same binding for global scope. Each
engine scope has a variable called "client", which is basically the
javascript object that represents the client. This object has methods
like tell, which uses that client's socket to send and receive data.
My problem is I can't seem to create a new thread and run a code in
it. Each time I do it, it seems to be running on a new scope hense
losing the client variable, which leaves me unable to contact with the
client. Here are my engine options:
engine=(NashornScriptEngine) factory.getScriptEngine(new
String[]{"-ot=true", "-doe", "--global-per-engine", "-strict"});
I thought global-per-engine might be the cause, but I can't get
clients to have their own client variable without it. Is this a bug?
How can I get my code to keep the engine scope in a new Thread which
is created like "new java.lang.Thread(function run() {
client.tell("hello"); });"
Please let me know if this is not clear enough and I'll try to explain
better along with code examples.

Thank you


More information about the nashorn-dev mailing list