Java 8 parallel sort - internals
Java 8 is a quite big update to the platform and luckily they focused on multicore systems too. The new Arrays.parallelSort() implementation is quite interesting: it is using quicksort, merge sort, and Timsort to achieve the best performance, depending on the underlying data type and size. Arrays.parallelSort() – not always parallel The first thing that needs to be noted is that it’s not always a parallel sort. If the array size is small enough (<= 8192 elements) or the number of reported logical CPUs is 1, it always falls back to a dual pivot quick sort. Note, that the “logical CPU” here refers to hyper-threading, so an average i7 dual core CPU will report 4 logical CPUs to the Java environment. To override the number of reported CPUs for the sort algorithm, we simply need to pass in any value to the following system property when starting the JVM: java.util.concurrent.ForkJoinPool.common.parallelism Sorting the chunks and chunk sizes The algorithm ( Arrays.java ) wi...