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
Step: 1
Answer import javautilconcurrentTimeUnit class SumThre...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started