Question: Can someone please help me with this java program please. Instructions are below: Develop a multithreaded program to calculate the summation of an array. This
Can someone please help me with this java program please. Instructions are below:
Develop a multithreaded program to calculate the summation of an array. This program will use two threads that share the same variable of summation.
// create SynchronizationDemo class
// the Synchronization should perform the steps below:
Main method should generate an integer array whose 100 elements are 1,2... 100. Generate the integer 100 times. Make two threads for the class Sum and use them to calculate the summation. of the 100 elements. The first thread should add the first half (50 elements) and the second thread should add the last half (50 elements) to the summation. Then display the summation.
// Create sum class
// The sum class should : implements Runnable interface.
The run method should calculate the total of the elements from index start to index end.
It should also Call Thread.sleep(5) to pause the thread.
Finally add the total to summation.
// Please document the program
Sample output: With synchronization Loop = 0 sum = 5050 Loop = 1 sum = 5050 Loop = 2 sum = 5050 ............. Loop = 99 sum = 5050 Without synchronization Loop = 0 sum = 1326 Loop = 1 sum = 5050 Loop = 2 sum = 1326 Loop = 3 sum = 5050 Loop = 4 sum = 5050 Loop = 5 sum = 5050 Loop = 6 sum = 3724 Loop = 7 sum = 5050 Loop = 8 sum = 5050 Loop = 94 sum = 5050 Loop = 95 sum = 5050 Loop = 96 sum = 5050 Loop = 97 sum = 5050 Loop = 98 sum = 5050 Loop = 99 sum = 5050
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
