Question

In: Computer Science

Multithreading Assignment In this homework, you will implement a multithreaded solution to finding the sum of...

Multithreading Assignment

In this homework, you will implement a multithreaded solution to finding the sum of 9,000,000 double values.

Begin, by creating a method that creates an array (not an arrayList) of 9000000 double’s and populates each index with a random number.

Create a class to hold the sum of all the numbers in the array. Protect access to that sum by using a ReentrantLock appropriately. This means that only methods in this class can access or modify the array and they should ALL lock the lock on entry and unlock upon exit even if just looking at a value. Make sure you use good object oriented techniques in creating this class.

Then, create a Runnable that can sum an array of any length and add that sum to a shared total. Separate the array into a minimum of 10 pieces and launch a thread to sum each of the pieces. You probably want more threads, but experiment to find number of threads that seems to sum the quickest.

When all threads are done summing their pieces, show the combined sum of all 9,000,000 pieces

Extra credit (up to 15 points out of 100) for creating a JavaFX GUI that graphically shows the percentage of the array summed and the growing sum.

Grading Criteria

Creates Runnable class sums an array

25

Appropriately launches at least 10 separate threads – more is fine

15

Updates the sum correctly

15

Appropriately protects shared data (sum) with lock(s)

15

Prints total sum in a readable fashion

15

Meets coding standards

15

Solutions

Expert Solution


Related Solutions

Write an application that uses multithreading to compute the sum of the integers in an array...
Write an application that uses multithreading to compute the sum of the integers in an array of size 100,000. You can populate the array with random numbers and your application should display the sum. (JAVA)
Write a C++ program where you implement a synchronized multithreaded version of HAPPY with four threads....
Write a C++ program where you implement a synchronized multithreaded version of HAPPY with four threads. The program will take in an array from 1 to n (n = 50) and will be passed to four different threads: If the current number is divisible by 2, then print HAP If the current number is divisible by 5, then print PY If the current number is divisible by both 2 and 5, then print HAPPY If the number is neither divisible...
1 Introduction This assignment requires the design and implementation of a multithreaded event scheduler. This will...
1 Introduction This assignment requires the design and implementation of a multithreaded event scheduler. This will give you an opportunity to write a multithreaded program that reads in and store event requests in any order and then executes the requests in order in real time. You will gain experience in writing a multithreaded program that uses timers, signals, signal handlers and semaphores to manage the use of a shared data structure. Your program will have two threads. The first thread...
Java-- For this homework you are required to implement a change calculator that will provide the...
Java-- For this homework you are required to implement a change calculator that will provide the change in the least amount of bills/coins. The application needs to start by asking the user about the purchase amount and the paid amount and then display the change as follows: Supposing the purchase amount is $4.34 and the paid amount is $20, the change should be: 1 x $10 bill 1 x $5 bill 2 x Quarter coin 1 x Dime coin 1...
designing a multithreaded application in C that determines whether the solution to a Sudoku puzzle is...
designing a multithreaded application in C that determines whether the solution to a Sudoku puzzle is valid A Sudoku puzzle uses a 9×9 grid in which each column and row, as well as each of the nine 3×3 subgrids, must contain all of the digits 1 to 9. main.c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <pthread.h> int puzzle[PUZZLE_SIZE+1][PUZZLE_SIZE+1]; int status_map[NUMBER_OF_THREADS];    parameters* worker_params[NUMBER_OF_THREADS]; pthread_t workers[NUMBER_OF_THREADS]; int main(int argc, char** argv) {    //Read the sudoku solution from  the file specified...
In this homework, you will implement a single linked list to store a list of employees...
In this homework, you will implement a single linked list to store a list of employees in a company. Every employee has an ID, name, department, and salary. You will create 2 classes: Employee and EmployeeList. Employee class should have all information about an employee and also a “next” pointer. See below: Employee Type Attribute int ID string name string department int salary Employee* next Return Type Function (constructor) Employee(int ID, string name, string department, int salary) EmployeeList class should...
In this homework you will implement a Library class that uses your Book and Person class...
In this homework you will implement a Library class that uses your Book and Person class from homework 2, with slight modifications. The Library class will keep track of people with membership and the books that they have checked out. Book.java You will need to modify your Book.java from homework 2 in the following ways: field: dueDate (private)             A String containing the date book is due.  Dates are given in the format "DD MM YYYY", such as "01 02 2017"...
Homework Arrays and Tables In this assignment you are to create an algorithm, flowchart, and pseudocode...
Homework Arrays and Tables In this assignment you are to create an algorithm, flowchart, and pseudocode for a solution of the following problem. This solution will include the use of arrays needed to complete all parts of the logic. You have requested to develop a program that will record and process the rainfall totals of a 12 month period. You would use an array to store each months total. Once all 12 months amounts are entered then your solution need...
(Python) Implement a function to compute a sum that can compute sum for an arbitrary number...
(Python) Implement a function to compute a sum that can compute sum for an arbitrary number of input integers or float numbers. In other words, calls like this should all work: flexible_sum(x1, x2) # sum of two integer or float numbers or strings x1 and x2 flexible_sum(x1, x2, x3) # sum of 3 input parameters and can also handle a single input parameter, returning it unchanged and with the same type, i.e.:   flexible_sum(1) returns 1 and can accept an arbitrary...
1.- In this assignment you will implement a simulation of the interaction of user programs with...
1.- In this assignment you will implement a simulation of the interaction of user programs with the OS to execute an I/O operation on two different devices. User programs: User programs will communicate with DOIO (OS) to request an I/O operation. (This will simulate a system call) User programs will give to DOIO three parameters: User id, device number (dev is a random number in the range 1 and 2 that represents device one or device two) and an address...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT