title: How to throttle method invocations to allow threads to complete
body: <p>I currently have the following setup. I am getting out fo memory exceptions after it runs for a little while; I suspect the for loop in main is causing too much of a backup method calls. What is the best way to throttle the calls if I don't wish to increase the thread pool size?</p>
  
  <pre><code>public class ManagedThreads {
     private final static ExecutorService ex = Executors.newFixedThreadPool(10);
  
     public static void myMethod(final int i) {
        ex.execute(new Runnable() {
           public void run() {
               // method body  using i
           }
        });
     }
  
     public static void main(String[] args) {
        for (int i = 0; i &lt; 1000000000; ++i)
           myMethod(i);
     }
  }
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>I meant to show that I am passing in the index for the loop to the runnables.</p>