title: Nashorn in thread safe manner
body: <p>Below I have shared my code in which I am trying to use thread safe Nashorn  as scripting engine to evaluate simple mathematical formula. Formula will be like "a*b/2" where a &amp; b will be picked up from map object. </p>
  
  <pre><code>public class EvaluateFormulas {
  
  @Autowired
  NashornThreadPool pool;
  
  private ScriptEngineManager factory;
  private ScriptEngine engine;
  private ScriptContext context;
  
  @PostConstruct
  public void setup() {
      factory = new ScriptEngineManager();
      engine = factory.getEngineByName("nashorn");
      context = engine.getContext();
  }
  
  public void evaluate() {
      pool.getThreadPoolExecutor().submit(new Runnable() {
          @Override
          public void run() {
              Double result;
              Bindings bind = engine.createBindings();
              bind.putAll(map);
              context.setBindings(bind, ScriptContext.GLOBAL_SCOPE);
              try {
                  result = (Double) engine.eval(formula);
              } catch (ScriptException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
          }
      });
  }   
  }
  </code></pre>
  
  <p>I need to know whether this approach will help making Nashorn thread safe for this use case. I read in Attila`s <a href="https://stackoverflow.com/questions/30140103/should-i-use-a-separate-scriptengine-and-compiledscript-instances-per-each-threa/30159424#30159424">answer</a> that we can share script engine objects between threads since they are thread safe.</p>
  
  <p>For bindings and eval, since we are creating new thread for each execution of <strong><em>evaluate</em></strong> and each thread has its own object reference for bindings object. So in its entirety, will this implementation be thread safe?</p>