1. Reimplement the concurrent Sorter class from Section 12.5 using a quicksort to control the recursion (rather than a mergesort). Beyond the Simple Sorter Class Our Sorter class is simple, but it...


1. Reimplement the concurrent Sorter class from Section 12.5 using a quicksort to control the recursion (rather than a mergesort).


Beyond the Simple Sorter Class


Our Sorter class is simple, but it provides a good basis for understanding concurrency. You can consider several expansions of the class’s functionality. For example, you might add the recursion threshold as an extra parameter to the constructor. There is also an alternative approach: Instead of using a recursion threshold, the constructor can have a parameter that specifies an exact number of threads to be used. If this number of threads is equal to 1, then the compute method uses java.util.Arrays.sort to sort the array in a single thread. And if the number of threads is greater than 1, then the compute method allows one of the recursive calls to use half of the threads, and the other to use the rest (see the answer to Self-Test Exercise 14).


Java also has support for concurrency beyond the RecursiveAction class. For example, RecursiveTask is a generic class similar to RecursiveAction in which the compute method returns a value of type T. In this case, the invokeAll method returns a collection of T objects that contains the results of all the separately invoked compute methods.





Dec 17, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here