Question: Program a multithreaded sum application in Java. The program will sum up all the numbers from 1 to 500,000,000. The result should be 125,000,000,250,000,000. Define

Program a multithreaded sum application in Java.

The program will sum up all the numbers from 1 to 500,000,000. The result should be 125,000,000,250,000,000.

Define a function for each of the following approaches. Each function should be timed so that it can print out how long the operation took.

Approach 1: Single threaded sum

Approach 2: Multithreaded sum. For this approach, test with a variable number of threads ranging from 2 to (at least) 10. The work should be split in numerical order. For example, having 2 threads, thread 1 should sum up the first half of the numbers and thread 2 should handle the second half.

Approach 3: Balanced multithreaded sum. For this approach, test with a variable number of threads ranging from 2 to (at least) 10. The work should be split in numerical order. For example, having 2 threads, thread 1 should sum up the odd numbers and thread 2 should handle the evens. With 3 threads, thread 1 would handle 1, 4, 7, ..., thread 2 would handle 2, 5, 8, ..., and thread 3 would handle 3, 6, 9, ..., etc.

Step by Step Solution

3.34 Rating (148 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Answer import javautilconcurrentTimeUnit class SumThre... View full answer

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 Operating System Questions!