Write ALL POSSIBLE outputs from the following multithreaded program (8pts). Explain your reasons (8pts). class Sum{...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write ALL POSSIBLE outputs from the following multithreaded program (8pts). Explain your reasons (8pts). class Sum{ private int sum; public int getSum(){ } return sum; } public void setSum(int sum){ this.sum = sum; } class Summation implements Runnable{ private int start; private int end; private Sum sumValue; public Summation(int start, int end, Sum sumValue) { this.start= start; this.end = end; this.sumValue = sumValue; public void run(){ } int sum = 0; for(int i=start; i<=end;i++) sum += i; sumValue.setSum(sum); System.out.println(" sum from " + start + " to "+ end + " is " + sum); } public class Test{ public static void main(String[] args){ int sum_total=0; int upper=10; Sum sumObject1=new Sum(); Sum sumObject2=new Sum(); Thread thrd1=new Thread(new Summation(1,upper/2-1, sumObject1)); Thread thrd2=new Thread(new Summation (upper/2,upper,sumObject2)); thrd1.start(); thrd2.start(); try{ thrd1.join(); thrd2.join(); sum_total sumObject1.getSum() + sumObject2.getSum(); System.out.println("the result is " + sum_total); } } }catch (Interrupted Exception ie) {} Write ALL POSSIBLE outputs from the following multithreaded program (8pts). Explain your reasons (8pts). class Sum{ private int sum; public int getSum(){ } return sum; } public void setSum(int sum){ this.sum = sum; } class Summation implements Runnable{ private int start; private int end; private Sum sumValue; public Summation(int start, int end, Sum sumValue) { this.start= start; this.end = end; this.sumValue = sumValue; public void run(){ } int sum = 0; for(int i=start; i<=end;i++) sum += i; sumValue.setSum(sum); System.out.println(" sum from " + start + " to "+ end + " is " + sum); } public class Test{ public static void main(String[] args){ int sum_total=0; int upper=10; Sum sumObject1=new Sum(); Sum sumObject2=new Sum(); Thread thrd1=new Thread(new Summation(1,upper/2-1, sumObject1)); Thread thrd2=new Thread(new Summation (upper/2,upper,sumObject2)); thrd1.start(); thrd2.start(); try{ thrd1.join(); thrd2.join(); sum_total sumObject1.getSum() + sumObject2.getSum(); System.out.println("the result is " + sum_total); } } }catch (Interrupted Exception ie) {}
Expert Answer:
Answer rating: 100% (QA)
Lets analyze the given multithreaded program class Sum private int sum publi... View the full answer
Related Book For
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch
Posted Date:
Students also viewed these programming questions
-
class MyThread extends Thread { MyThread() {} MyThread(Runnable r) {super(r); } public void run() { System.out.print("Inside Thread "); } } class MyRunnable implements Runnable { public void run() {...
-
Your task is to modify the worked-example of ABC Wash Machine and print out the above statistical information. public class Clock { private int hr; //store hours private int min; //store minutes...
-
2. Using the data below, create the project schedule using normal times. Determine the order in which you would crash the project one day, two days, and so on until it is in an all-crash mode....
-
1. Discuss why knowledge management is crucial to the success of an organization. How does a company implement knowledge management and what are the processes for implementing it? Discuss the...
-
The following data set belongs to a sample: Calculate the mean, median, and mode. 14 1810 8 8 -16
-
Give two arguments for and two arguments against partial-birth abortions.
-
Why are convertible bonds less risky than stock but usually more risky than nonconvertible bonds?
-
what is time complexity of the following code? void function ( ) { int sum = 0 ; for ( int i = 1 ; i < = 1 0 0 ; i + + ) { int x = i; while ( x ! = 0 ) { sum + = x; x / = 2 ; } } printf ( " % d " ,...
-
If someone asked you to define the features of a sense of guilt, apparently uncaused fear, and apparently uncaused fleeing, how would you explain each one? Discuss: Use the Bible to support your...
-
Calculate the maximum premium that Jayne would be prepared to pay to insure herself against the total loss of her house worth 100,000 if her initial level of wealth was 140,000 and comment on your...
-
Using the balances of T-accounts , prepare a trial balance. 11/1 Bal. 11/10 11/12 11/29 11/30 Bal. 11/1 Bal. 11/27 11/50 Bal 11/1 Bal. 11/17 11/30 Bal. 3,640 1,860 3,810 750 4,710 3,120 970 2,230...
-
BGJ Corporation had no short-term investments prior to this year. It had the following transactions this year involving short-term stock investments with insignificant influence. April 16 July 7 July...
-
6. Consider the linear optimization model Maximize 2x + y Subject to x + 2y 8 x - y 5 x,y 20 (a) Graph the constraints and identify the feasible region. (b) Choose a value and draw a dotted line...
-
The following information is taken from the book of Barreto Resources Berhad for the month of June 2019. Cash Accounts Receivable Prepaid Insurance Prepaid Rent Supplies Equipment Vehicle Accounts...
-
See Clear Company manufactures clear plastic CD cases. It applies variable overhead based an the number of machine hours used, Information regarding See Clear's overhead for the month of December...
-
Consider the discrete group G of order 8 that has the following Cayley diagram e If we have the sequence of operations: fcagec, which of the options represents the reduction of the sequence to a...
-
Write a Java program that serves as a primitive web browser. For this assignment it merely needs to input a server name and display the HTML that is sent by the web server. A web server normally...
-
Consider the following fragment of code: if (x > 5) { System.out.println("A"); if (x < 10) System.out.println("B"); } else System.out.println("C"); What is displayed if x is a. 4; b. 5; c. 6; d. 9;...
-
Write Java statements that create a yes-or-no dialog box to answer the question, Are you in college?
-
What is the current ratio? A. 0.2 B. 2.0 C. 1.7 D. 0.8 E. 1.2 Using the following balance sheet and income statement Balance sheet m Property 200 Trade payables Plant and equipment 300 Tax due Other...
-
What is the quick (acid test) ratio? A. 0.9 B. 4.8 C. 0.8 D. 0.2 E. 1.7 Using the following balance sheet and income statement Balance sheet m Property 200 Trade payables Plant and equipment 300 Tax...
-
What is the receivables holding period? A. 21.6 days. B. 8 times. C. 19.4 days. D. 4.7 times. E. 28.2 days. Using the following balance sheet and income statement Balance sheet m Property 200 Trade...
Study smarter with the SolutionInn App