Anyone can clarify whether NashornScriptEngine is thread-safe or not? If it is not thread-safe, how to handle multiple scripts?
The engine itself is thread-safe but the answer isn't a simple yes/no so keep on reading.
Please see this answer from someone with excellent credentials on this topic.
I'm not going to copy/paste the entire answer, but it starts off with this:
You can share a ScriptEngine and CompiledScript objects across threads. They are threadsafe. Actually, you should share them, as a single engine instance is a holder for a class cache and for JavaScript objects' hidden classes, so by having only one you cut down on repeated compilation.
What you can't share is Bindings objects ...
Make sure to read the rest of the answer!