title: How come my Java program goes faster when I execute a number of parallel threads superior to Runtime.getRuntime().availableProcessors())?
body: <p>I have done some research on how to execute parallel threads in Java.
  I have found an easy solution, which is to use <code>ExecutorService</code> class.
  It is basically used by calling the following:</p>
  
  <pre><code>ExecutorService es = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
  </code></pre>
  
  <p>Each thread executes a simple task, such as a <code>System.out.println()</code>.</p>
  
  <p>I have been told that <code>Runtime.getRuntime().availableProcessors()</code> returns the number of processors, which is basically the number of execution engines capable of running your code, physically distinct or logical processors, if using hyper-threading.</p>
  
  <p>However, when I use the following line instead:</p>
  
  <pre><code>ExecutorService es = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()*2);
  </code></pre>
  
  <p>my program actually goes a lot faster (even though I haven't calculated the exact running time, simply observing the obvious change in speed).</p>
  
  <p>How is this possible? Also, if I multiply the number by three, it speeds up even more, even though the speed stops increasing with higher factors.</p>
  
  <p>My computer is a MacBook Pro running on Yosemite, with a 2,2 GHz Intel Core i7 processor.</p>