Question: Revise Listing 32.10, ParallelMergeSort.java, to define a generic parallelMergeSort method as follows: public static > void parallelMergeSort(E[] list) Data from Listing 32.10, 1mport java.util.concurrent. RecursiveAction;

Revise Listing 32.10, ParallelMergeSort.java, to define a generic parallelMergeSort method as follows:

public static > void
parallelMergeSort(E[] list)


Data from Listing 32.10,

1mport java.util.concurrent. RecursiveAction; 2 1mport java.util.concurrent. ForkJoinPool; 4 publ1c class ParallelMergeSort {

publ1c stat1c void main(String[] args) { final int SIZE = 7000000; 1nt[]

1mport java.util.concurrent. RecursiveAction; 2 1mport java.util.concurrent. ForkJoinPool; 4 publ1c class ParallelMergeSort { publ1c stat1c void main(String[] args) { final int SIZE = 7000000; 1nt[] list1 = new int[SIZE]: int [] list2 = now int[SIZE]: 5 6 7 8 for (1nt i = 0: 1 < list1.length; i++) listi[i] = list2[i] = (1nt) (Math.random () 10000000); 10 11 12 Tong startTime = System.currentTimeMillis (): parallelMergeSort (list1):: // Invoke parallel merge sort Tong endTime = System.currentTimeMillis (): System.out. printin(" Parallel time with " + Runtime.getRuntime ().availableProcessors () + " processors 1s " + (endTime - startTime) + " m1111seconds"): 13 14 15 16 17 18 19 20 startTime = System.currentTimeMillis(): MergeSort.mergeSort (list2); // MergeSort is in Listing 23.5 endTime = System.currentTimeMillis (): System.out.printin("inSequential time 1s "+ (endTime - startTime) + " m1111seconds"): 21 22 23 24 25 26 public static void parallelMergeSort (1nt [] 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 = 500; 34 1234t 567 o

Step by Step Solution

3.40 Rating (169 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

import javautilconcurrentRecursiveAction import javautilconcurrentForkJoinPool public class Exercise3213 public static void mainString args final int SIZE 700000 Integer list1 new IntegerSIZE Integer ... 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 Introduction to Java Programming and Data Structure Questions!