Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help URGENT In this project, you will develop a multithreaded program for calculating the summation of elements in an array. The program uses mutex

Please help URGENT
In this project, you will develop a multithreaded program for calculating the summation of elements in an array. The program uses mutex lock for synchronization. To use multi-threaded programing, the array of integers is divided into two smaller sublists. Two separate threads add the elements in the first half and second half of the array to the summation. To demonstrate the benefits of synchronization for multi-threaded program, the program repeats the procedure for 100 times where the results should always be the same.
This program will require the two threads share the same variable of summation. Summing the elements of the sublists to a local variable can be concurrent. But adding the results to the summation should be synchronized.
Program Structure
The program consists of the following Classes:
1. SynchronizationDemo: main method performs the following tasks:
1) Generate an integer array whose 100 elements are 1,2, 3,... 100
2) Repeat the following 100 times:
i. Create two threads for the class Sum and use them to calculate the summation of the 100 elements. The first thread adds the first 50 elements to the summation, and the second thread adds the second 50 elements to the summation.
ii. Display the summation.
2. Sum: an inner class that implements Runnable interface. run method performs the following tasks:
1) Calculate the total of the elements from index start to index end
2) Call Thread.sleep(5) to pause the thread
3) Add the total to summation

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_2

Step: 3

blur-text-image_3

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

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions