title: java scripting with mozilla rhino and memory management problem
body: <p>I'm building an javascript api that will call some java objects using mozilla rhino.</p>
  
  <p>Everything is good and nice, however I want to avoid unlimited looping that could slow my java application.</p>
  
  <p>for example (in javascript):</p>
  
  <pre><code>while(true) doSomething(); // doSomthing will call a method in java
  </code></pre>
  
  <p>In modern browsers after a certain time an error appears telling the script is making the application to run slow, and if I want to continue and stop script.</p>
  
  <p>I want to implement this on my java application if it's possible, but I don't know how.
  The only solution I can think about is to count the number of methods are being called per second , and if it's a huge number to stop the script. DO you have any other ideas?</p>