Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 11 The Ultimate Database For Cloud Analytics And Mobile

Authors: John Campbell, Chris Crone, Gareth Jones, Surekha Parekh, Jay Yothers

1st Edition

ISBN: 1583474013, 978-1583474013

Students also viewed these Databases questions

Question

Approaches to Managing Organizations

Answered: 1 week ago

Question

Communicating Organizational Culture

Answered: 1 week ago