NashornScriptEngine 是线程安全的吗?

Is NashornScriptEngine thread-safe?

谁能说明一下 NashornScriptEngine 是不是线程安全的? 如果不是线程安全的,如何处理多个脚本?

引擎本身是线程安全的但答案并不简单yes/no所以请继续阅读。

请参阅此 来自在此主题上具有出色资历的人。

我不会 copy/paste 完整的答案,但它是这样开始的:

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 ...

确保阅读 的其余部分!