Caching of CompiledScripts and related time zone issues
Martin.Hiller at cas.de
Mon Nov 28 10:32:12 UTC 2016
we are using Nashorn in a web application scenario where currently each session has its own scripting engine. As most of the executed scripts are the same across the different sessions, we actually want to employ a single engine for the whole application and benefit from the common class cache and globally cached CompiledScripts (of course every script would be executed with a separate Global/Bindings).
However, each session potentially needs to run scripts in its own time zone, which can afaik only be set during engine creation. So it seems to me that one engine per session (or at least one engine per time zone) is the minimum requirement in our scenario, isn't it?
On the other hand, if we stick to our one-engine-per-session rule, it seems impossible to cache and reuse CompiledScripts on a global level because a CompiledScript is tied to the engine it was created from, and this CompiledScript will therefore always use the time zone of its corresponding engine.
Is there an easy method or workaround to profit from global caching of compiled scripts in a way that the time zone is retrieved at script runtime and not fixed at engine creation time? Or do you have any other suggestion on how to improve the depicted scenario?
Thank you for your time!
More information about the nashorn-dev