public class ParallelSort2 extends Object
ParallelSort
in that it performs merge operations concurrently, not just the sorting
of chunks.
The merge step is parallelized by merging two adjacent chunks in a single thread. So if there are eight chunks, up to four threads can be utilized to merge them. In this example, once the eight chunks are merged into four, up to two threads can be utilized to merge those. The final step can only be done in one thread and it merges the last two chunks into the final sorted list.
ParallelSort
,
SlowParallelSort
Constructor and Description |
---|
ParallelSort2() |
Modifier and Type | Method and Description |
---|---|
static <T> void |
sort(List<T> list,
Comparator<? super T> comparator,
int requestedNumThreads)
Sorts the specified list using the specified executor for running concurrent sub-tasks.
|
static <T extends Comparable<T>> |
sort(List<T> list,
int requestedNumThreads)
Sorts the specified list using the specified executor for running concurrent sub-tasks.
|
public static <T extends Comparable<T>> void sort(List<T> list, int requestedNumThreads)
T
- the type of element in the listlist
- the list to sortrequestedNumThreads
- the number of threads to useNullPointerException
- if any of the reference arguments are null or if the specified
list contains any null elementsIllegalArgumentException
- if the specified number of threads is zero or negativeRuntimeException
- if this thread is interrupted while waiting on parallel operations
to completepublic static <T> void sort(List<T> list, Comparator<? super T> comparator, int requestedNumThreads)
T
- the type of element in the listlist
- the list to sortcomparator
- the comparator to use for ordering items relative to one anotherrequestedNumThreads
- the number of threads to useNullPointerException
- if any of the reference arguments are null or if the specified
list contains any null elementsIllegalArgumentException
- if the specified number of threads is zero or negativeRuntimeException
- if this thread is interrupted while waiting on parallel operations
to complete