Java & Usage of Multicore CPUs

The assumption is that the operating system will allocate threads to multiple cores. Assuming the OS is providing this support:


This article describes writing a sort routine to use multiple cores:

Simple version:

  1. Figure out how many pieces (threads) you will break the task into.
  2. Set up a CountDownLatch for the number of pieces.
  3. When each piece (thread) finishes, decrement the CountDownLatch
  4. After you've started the threads use CountDownLatch.await() to
    wait for all the threads to finish.
  5. Do whatever you need to merge the results.