title: java scripting API - how to stop the evaluation
body: <p>i have writen a servlet that recives a java script code and process it and returns the answer. for that i have used the java scripting API</p>
  
  <p>in the code below if script = "print('Hello, World')"; the code will end properly print "hello world".
  but if script = "while(true);" the script will loop endlessly.</p>
  
  <pre><code>import javax.script.*;
  public class EvalScript {
      public static void main(String[] args) throws Exception {
          // create a script engine manager
          ScriptEngineManager factory = new ScriptEngineManager();
          // create a JavaScript engine
          ScriptEngine engine = factory.getEngineByName("JavaScript");
          // evaluate JavaScript code from String
          engine.eval(script);
      }
  }
  </code></pre>
  
  <p>my question is how do i kill the eval process in case it takes too long (lets say 15 sec)?</p>
  
  <p>thanks</p>