1

I have already read these threads:

  1. Reuse Nashorn ScriptEngine in Servlet

  2. Should I use a separate ScriptEngine and CompiledScript instances per each thread?

My requirement is somewhat different and I want some guideline. I am required to evaluate a different javascript snippet in each request served by the servlet. Some of the servlet arguments will lead me to a database table row, where the applicable javascript code snippet is stored. I will fetch that javascript code snippet and evaluate it in the request (processing some of the other arguments of the servlet) and return the results in the response.

So my question is, in order to handle multithreading, memory and efficiency where best (in init method or servlet constructor or POST method ... or where?) should I create the Script Engine? Where should I put the bindings? and where should I compile/invoke the javascript?

Any help, example, tutorial link is appreciated.

Thanks in advance.

Community
  • 1
  • 1
user1940163
  • 191
  • 2
  • 7

0 Answers0