Question: why is this code not running? it compiles but... import java.util.ArrayList; import java.util.Collections; import java.util.List; //import java.util.Random; public class EmployeeSorter { public static void main(String[]

why is this code not running? it compiles but... import java.util.ArrayList; import java.util.Collections; import java.util.List; //import java.util.Random; public class EmployeeSorter { public static void main(String[] args) throws InterruptedException { List EmpList = new ArrayList(); for (int i = 1; i <= 10000; i++) { EmpList.add(new Employee(i, (int) (Math.random() * 2500 + 1500))); } List List1 = EmpList.subList(0, EmpList.size() / 2); List List2 = EmpList.subList(EmpList.size() / 2, EmpList.size()); Thread thread1 = new Thread(); Collections.sort(List1); Thread thread2 = new Thread(); Collections.sort(List2); thread1.start(); thread2.start(); thread1.join(); thread2.join(); int i = 0, j = 0; for (int k = 0; k < EmpList.size(); k++) { if (i < List1.size() && j < List2.size()) { if (List1.get(i).compareTo(List2.get(j)) < 0) { EmpList.set(k, List1.get(i++)); } else { EmpList.set(k, List2.get(j++)); } } else if (i < List1.size()) { EmpList.set(k, List1.get(i++)); } else { EmpList.set(k, List2.get(j++)); } } } }

This is the question

In this question, we need to divide, sort, and merge a list of Employees using the multithreading framework. Create a class named EMPLOYEE that holds the employees ID (integer value of unique value) and salary (integer value).

Step1: The main thread creates a list of 10,000 Employees with sequential IDs (1 to 10,000 to keep them unique) and randomly generated salaries (between 1500 to 4000); name this list EmpList.

Step2: Split the generated list EmpList into two lists of equal length: List1, and List2. Step3: Create two threads; each thread should sort the corresponding list (thread1 sorts List1, and thread2 sorts List2)

ascendingly with respect to the salary.

Step4: The main thread then waits for the two threads, then merge the two sorted sublists (List1 and List2) into the main list (EmpList) ascendingly with respect to the salary.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!