title: using java scripting API to find and destroy bad/malicious java script code
body: <p>I am working on a servlet (runs on tomcat) which receives requests that contains Java Script code, and using the java scripting API framework evaluates/run the code and returns the answer to the user.</p>
  
  <p>Since we are dealing with user generated code, the code can be a good code and it can be bad code. As an example for a bad code can be while(true); which will endlessly loop in the server taking unnecessary resources </p>
  
  <h2>my questions</h2>
  
  <p>1) how can i discover a bad code? 
  2) once identified as a bad/malicious code what is the best way to stop the run?</p>
  
  <p>thanks</p>