1

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

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

It works, but it's extremely inefficient as my unchanging JavaScript is evaluated every time. What's the proper way to re-use the evaluated JavaScript?

Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622
  • Related. Nas Horn has cache for evaluated scripts. I guess, you are looking for much more than that. https://blogs.oracle.com/nashorn/entry/latest_news_from_the_nashorn – Jayan Aug 27 '15 at 15:04
  • @Jayan I read that question, but CompiledScript has no way to invoke a method, you need to invoke it in the engine, so I don't understand what's the point of the CompiledScript and how this whole set up provides re-usability of the script. – Pablo Fernandez Aug 27 '15 at 15:07
  • Okay- I will delete that link.. – Jayan Aug 27 '15 at 15:19

0 Answers0