title: How Java multi-threaded program is able to use multiple CPU cores?
body: <p>Could someone please provide explanation how Java multi-threaded program (e.g. Tomcat servlet container) is able to use all cores of CPU when JVM is only single process on linux? Is there any good in-depth article that describes the subject in details?</p>
  
  <p><strong>EDIT #1</strong>: I'm not looking for advice how to implement multi-threaded program in Java. I'm looking for explanation of how JVM internally manages to use multiple cores on linux/windows while still being single process on the OS.</p>
  
  <p><strong>EDIT #2</strong>: The best explanation I managed to find is that Hotspot (Sun/Oracle JVM) implements threads as native threads on Linux using NPTL. So more less each thread in Java is lightweight process (native thread) on Linux. It is clearly visible using <code>ps -eLf</code> command that print outs not only process id (<code>PPID</code>) but also native thread id (<code>LWP</code>). </p>
  
  <p>More details can be also found here:</p>
  
  <ul>
  <li><a href="http://www.velocityreviews.com/forums/t499841-java-5-threads-in-linux.html" rel="nofollow noreferrer">http://www.velocityreviews.com/forums/t499841-java-5-threads-in-linux.html</a></li>
  <li><a href="https://stackoverflow.com/questions/1888160/distinguish-java-threads-and-os-threads">Distinguishing between Java threads and OS threads?</a></li>
  </ul>
  
  <p><strong>EDIT #3</strong>: Wikipedia has short but nice entry on NPTL with some further references <a href="http://en.wikipedia.org/wiki/Native_POSIX_Thread_Library" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Native_POSIX_Thread_Library</a></p>