Threading Problem with Nashorn
attila.szegedi at oracle.com
Tue Jul 9 03:34:45 PDT 2013
thanks for experimenting with Nashorn!
As far as your example is concerned, Nashorn is not thread safe by design. Indeed, if you evaluate
it'll return null, which means "the engine implementation is not thread safe, and cannot be used to execute scripts concurrently on multiple threads" -- see <http://docs.oracle.com/javase/7/docs/api/javax/script/ScriptEngineFactory.html#getParameter(java.lang.String)>
As I said, this is by design. ECMAScript 5.1 language specification doesn't define multithreading semantics for programs written in the language; they are inherently single threaded. If we were to make them thread safe, we'd be sacrificing single threaded performance for a behavior that falls outside of the specification. You can always create one script engine per thread using the same factory - that should work in a multithreaded scenario.
On Jul 9, 2013, at 10:01 AM, Tobias Schlottke <tobias.schlottke at gmail.com> wrote:
> Hi there,
> we're currently planning to switch our infrastructure from Rhino to Nashorn but are experiencing some threading Issues that nobody addressed so far.
> I tweeted with Jim Laskey and he kindly asked me to post it to this list.
> Could could you check this example and check if this really is a problem in your eyes or if it is supposed to be this way?
More information about the nashorn-dev