title: When does concurrency/multithreading help improve performance?
body: <p>I have been planning to use concurrency in project after learning it indeed has increased through put for many.
  Now I have not worked much on multi threading or concurrency so decided to learn and have a simple proof of concept before using it in actual project.<br/>
  Below are the two examples I have tried:</p>
  
  <pre><code>1. With use of concurrency
  
      public static void main(String[] args) 
  
      {
          System.out.println("start main ");
  
          ExecutorService es = Executors.newFixedThreadPool(3);
          long startTime = new Date().getTime();
          Collection&lt;SomeComputation&gt; collection = new ArrayList&lt;SomeComputation&gt;();
          for(int i=0; i&lt; 10000; i++){
              collection.add(new SomeComputation("SomeComputation"+i));
          }
          try {
              List&lt;Future&lt; Boolean &gt;&gt; list = es.invokeAll(collection);
          } catch (InterruptedException e) {
              e.printStackTrace();
          }
          System.out.println("\n end main "+(new Date().getTime() - startTime));
      }
  
  2. Without use of concurrency
  
          public static void main(String[] args) {
  
            System.out.println("start main ");
            long startTime = new Date().getTime();
            Collection&lt;SomeComputation&gt; collection = new ArrayList&lt;SomeComputation&gt;();
            for(int i=0; i&lt; 10000; i++){
            collection.add(new SomeComputation("SomeComputation"+i));
          }
          for(SomeComputation sc:collection)
          {
          sc.compute();
          }
          System.out.println("\n end main "+(new Date().getTime() - startTime));
          }
  
      Both share a common class
  
          class SomeComputation implements Callable&lt;Boolean&gt;
          {
              String name;
              SomeComputation(String name){this.name=name;}
              public Boolean compute()
              {
                  someDumbStuff();
                  return true;
              }
  
              public Boolean call()
              {
                  someDumbStuff();
                  return true;
              }
  
              private void someDumbStuff()
              {
                  for (int i = 0;i&lt;50000;i++)
                  {
                      Integer.compare(i,i+1);
                  }
                  System.out.print("\n done with "+this.name);
              }
          }
  </code></pre>
  
  <p>Now the analysis after 20 odd runs of each approach.<br/>
  1st one with concurrency takes on average 451 msecs.<br/>
  2nd one without concurrency takes on average 290 msecs.<br/>
  Now I learned this depends on configuration , OS , version(java 7) and processor.
  But all was same for both approaches.
  Also learned the cost of concurrency is affordable on when computation is heavy.But this point wasn't clear to me. <br/>
  Hope some one can help me understand this more.<br/>
  PS: I tried finding similar questions but could find this kind.Please comment the link if you do.</p>