Question: Revise Listing 30.10, ParallelMergeSort.java, to define a generic parallelMergeSort method as follows: Listing public static void parallelMergeSort(E[] list) 1 import java.util.concurrent.RecursiveAction; 2 import java.util.concurrent. ForkJoinPool;

Revise Listing 30.10, ParallelMergeSort.java, to define a generic parallelMergeSort method as follows:public static void parallelMergeSort(E[] list) 1 import java.util.concurrent.RecursiveAction; 2 import java.util.concurrent. ForkJoinPool;

Listing

3 4 public class ParallelMergeSort { public static void main(String[] args) {

final int SIZE = 7000000; int[] listl = new int[SIZE]; int[] list2

public static void parallelMergeSort(E[] list) 1 import java.util.concurrent.RecursiveAction; 2 import java.util.concurrent. ForkJoinPool; 3 4 public class ParallelMergeSort { public static void main(String[] args) { final int SIZE = 7000000; int[] listl = new int[SIZE]; int[] list2 = new int[SIZE]; 5 for (int i = 0; i < list1.length; i++) list1[i] = list2[i] = (int)(Math.random() * 10000000); 10 11 12 13 14 15 16 17 18 19 20 21 22 long startTime = System.currentTimeMillis(); parallelMergeSort(list1); // Invoke parallel merge sort 1ong endTime = System.currentTimeMillis(); System.out.printin(" Parallel time with + Runtime.getRuntime().availableProcessors() + processors is " + (endTime - startTime) + "milliseconds"); startTime = System.currentTimeMillis(); MergeSort.mergeSort(1ist2); // MergeSort is in Listing 23.5 endTime = System.currentTimeMillis(); System.out.println(" Sequential time is " + (endTime - startTime) + " milliseconds"); 23 24 25 26 public static void parallelMergeSort(int[] list) { RecursiveAction mainTask = new SortTask(list); ForkJoinPool pool = new ForkJoinPool(); pool.invoke (mainTask); 27 28 29 30 31 32 { 33 private static class SortTask extends RecursiveAction { private final int THRESHOLD 34 500;

Step by Step Solution

3.33 Rating (156 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Program Plan Design a generic solution to the parallel merge sort problem using data type making the type generic Useas the datatype to make the program accept any primitive datatype as method argumen... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Java Programming Questions!