Question
(JAVA) Modify the above code with the following requirements: - The above code only reads one integer input from the user on Console. You need
(JAVA) Modify the above code with the following requirements:
- The above code only reads one integer input from the user on Console. You need to change the code to read a sequence of integer inputs and store them into an array, i.e., arrUpper
- Add code to prompt the user to enter the number of threads in the pool. Then, read the user input into an integer variable such as num_thread_pool
- Besides the newSingleThreadExecutor() method, the ExecutorService class supports another method to create a fixed-size thread pool: newFixedThreadPool(int size). Now, modify the above code to change from newSingleThreadExecutor() to newFixedThreadPool(). You need to use the above num_thread_pool variable to pass to this method.
- Finally, modify the two lines of code inside the try block to use a for loop to submit a new Summation task instance of each element in the array arrUpper
c. Run your modified code with the same numbers of the input integers but changing the input number of threads in the pool. Compare the execution time with such a different number of threads in the pool and discuss your findings.
- Below is a sample output of the modified program to give you an idea of how to modify the given code correctly:
import java.util.Scanner; import java.util.concurrent.*; class Summation implements CallableStep by Step Solution
There are 3 Steps involved in it
Step: 1
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