title: Multithreaded quicksort or mergesort
body: <p>How can I implement a concurrent quicksort or mergesort algorithm for Java?</p>
  
  <p>We've had issues on a 16-(virtual)-cores Mac where only one core (!) was working using the default Java sorting algo and it was, well, not good to see that very fine machine be completely underused.  So we wrote our own (I wrote it) and we did indeed gain good speedups (I wrote a multithreaded quicksort and due to its partitioning nature it parallelize very well but I could have written a mergesort too)...  But my implementation only scales up to 4 threads, it's proprietary code, and I'd rather use one coming from a reputable source instead of using my re-invented wheel.</p>
  
  <p>The only one I found on the Web is an example of how <strong>not</strong> to write a multi-threaded quicksort in Java, it is busy-looping (which is really terrible) using a:</p>
  
  <pre><code>while (helpRequested) { }
  </code></pre>
  
  <p><a href="http://broadcast.oreilly.com/2009/06/may-column-multithreaded-algor.html" rel="noreferrer">http://broadcast.oreilly.com/2009/06/may-column-multithreaded-algor.html</a></p>
  
  <p>So in addition to losing one thread for no reason it's making sure to kill the perfs by busy-looping in that while loop (which is mindboggling).</p>
  
  <p>Hence my question: do you know of any correctly multithreaded quicksort or mergesort implementation in Java that would be coming from a reputable source?</p>
  
  <p>I put the emphasis on the fact that I know that the complexity stays O(n log n) but I'd still enjoy very much to see all these cores start working instead of idling.  Note that for other tasks, on that same 16 virtual cores Mac, I saw speedup of up to x7 by parallelizing the code (and I'm by no mean an expert in concurrency).</p>
  
  <p>So even tough the complexity stays O(n log n), I'd really appreciate a x7 or x8 or even x16 speedup.</p>