title: Java Concurrency Threading Error
body: <p>I have a list of 100 strings. For each string I need to perform 3 tasks.
  So I introduced Concurrent threads</p>
  
  <pre><code>Class A implements Runnable
  {
  
    String str;
    A(String s)
    {
      str = s;
    }
  
    public static void main(String[] args)
     {
       Runnable runnable = null;
  
        //For Each of my strings
        for(String s:MyList)
        {
            runnable = new A(s);
            new Thread(runnable).start();
        }
    }
  
     @Override
     public void run() {
         task1();
         task2();
         task3();
     }
   }
  </code></pre>
  
  <p>This Runs into an Exception. </p>
  
  <p>Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded
  Exception in thread "Thread-0" java.lang.OutOfMemoryError: Java heap space</p>
  
  <p>How do I overcome this and restrict the Thread size? </p>
  
  <p>I tried Using this. </p>
  
  <pre><code>ExecutorService pool = Executors.newFixedThreadPool(10);
  pool.execute(runnable);
  </code></pre>
  
  <p>It doesnt work. </p>