Assignment 5 : Multi-Treaded - Multi-Level Two-Way Merge Sort Dr. Huaqing Wang I. Introduction to Threading - A process is running program with its running envirment data. - A thred is a runnning program with its data as part of a running progra of a process. - One or (usually) multiple threads are running under a process. - Threads are also called light-weight process. One of reasons for being light-weight is switching CPU among threads of the same process takes shorter time time than switch CPUS among the processes. - In Java, the following can be used to create and run threads I-1: Define classes that extends Thread class and - override 'public void run()' (in my poinion, it shoud be called 'public void miniMain( String args[])'. Add constructors and other functions. - Create (Thread) objects of this classes, and then call start() to run. (In my optinion call .miniMain( argument-list ) to run objects. I-2: Define classes that implements Runnable inferface and - override 'public void run()' (in my poinion, it shoud be called 'public void miniMain( String args[])'. Add constructors and other functions. - Create runnable objects of this runnblw classes, - Create Thread object and pass a runnable object as argument. Call start() from the thread objects. Method I-2 is prefered. II. Sorter Threads - A sorter willl give a array of data, starting location, and size of section to work on. - Create MaxHeap object and poss array, starting address and size to heap to sort on. - You need MaxHeap so that data will be in acending order. - Multiple sorted threads will be used to sort sections concurrently. III. 2-Way Merger Threads - A merger will merge two adjecent and sorted sections into a larger section. - The sorrted sections are in one array and the merged result will in different array. - A merger should wait for sorter to complete, and start to merge. - A merger should have following objects (paramters): source-array, sorter1-to-wait, sorter2-to-wait, destination-array, starting-idx while the starting-idx is the starting location that merger will put data in. IV. To Test Your Implementation with the following Menu-Driven Program: ============================ 3390 Assignment 5 ========================== Multi-Threaded Multi-Leval Two-Way Meree Sort. ========================================================================= G/g: 1. Ask N for array size. 2. Create two arrays of Some sizes. fill the fist array with random integers. 3. Fille first array into 4 sections, 4. Create 4 sorter threads and each sorter sorts one section. 5. Create two levels of mergers, the level for merging the sorters's results has two merger, each of them wainging two sorters. The next level of mergers has one merger which merges the result of two mergers. S/s: 1. Show the results of two array with 10 values per line, and 20 lines per screen. After each screen, Q/q will stop listing and RETURN without letter to contiune. 2. Print out the array which contains the final sorted result after the other array. ========================================================================= H/h/?: Show this menu. E/e: Exit the project. =========================================================================