Reusing Nashorn ScriptEngine

I have the following code that I run for each HTTP request:

ScriptEngine jsEngine = ScriptEngineManager.new().getEngineByName("nashorn"); jsEngine.eval("some script"); jsEngine.invokeMethod(jsEngine.eval("foo"), "bar"); 

It works, but it is extremely inefficient, as my immutable JavaScript is evaluated every time. What is the correct way to reuse evaluated JavaScript?

+1
source share

All Articles