Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

Question

Generate a new Java Project in Eclipse and complete following requirements based on the Threads. Some threads will share a single object and contribute their individual result to shared object. The shared object accumulates partial results. Make a package named cs520.hw6. Using this package, produce the following classes.

1. Generate a class named SharedResults as follows. The class keeps track of shared result.

a. The instance (or member) private variable result (int).

b. A void addToResult process that takes the given integer argument and adds it to the shared result. This method then prints to the console the name of the current thread, the value it added, and the cumulative result. Handle the synchronization issue with this method.

c. The getResult method with no arguments which returns the shared result. Handle synchronization issue with this method.

2. Generate a class named LongTask that extends the Thread class.

a. The instance (or member) private variables sharedData (of type SharedResults), start (integer) and end (integer).

b. A single constructor which takes the above three arguments and stores them in the instance values. Also, create a name for this thread as Thread_<start>_<end>

c. In the run method, add the integer numbers from start to end (both inclusive) using a for loop. Also, sleep for a random time (up to 10 milliseconds) in each iteration of the loop. After loop, invoke the addToResult technique of shared object and provide this accumulated sum.

3. Produce a Test class to test following functionality in its key method.

a. make the SharedResults object and assign it to a variable.

b. generate five LongTask objects by passing the above shared object and the start and end values for each as (1, 100), (101, 200), (201, 300), (301, 400), and (401, 500) respectively.

c. Start each thread as it is formed.

d. Wait for all the threads to complete using joins method.

e. Print result from the shared object.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M9719031

Have any Question?


Related Questions in Computer Engineering

Explain the difference between penetration tests and

Explain the difference between penetration tests and security tests. Emphasize that this book will explain things from a security testing perspective.

Assignment 1 project proposalyou have been selected to be

Assignment 1: Project Proposal You have been selected to be the project manager (for a project of your choice). The project that you decide to use should meet all the key criteria of a project as outlined in the PMBOK, s ...

Explain that the biggest problems with adware is that it

Explain that the biggest problems with adware is that it slows down the computers its running on.

A confidence interval for a population mean is to be

A confidence interval for a population mean is to be estimated. The population standard deviation is guessed to be anywhere from 14 to 24. The half-width B desired could be anywhere from 2 to 7. Tabulate the minimum samp ...

Subject economicsa manager has a utility function u c 05

Subject: Economics A manager has a utility function U = C 0.5 if she doesn't work hard and U = C 0.5 - 3 if she does. Expected profit will increase from 1,000 to 1,500 if she works hard. The manager receives compensation ...

Can someone please code this simple background subtraction

can someone please code this simple background subtraction but with height and width ratio to detect a human being. Please! I so badly need it for my dissertation,, cant make a loop that would subtract the every frame fr ...

Your task in this assignment is to create a threaded class

Your task in this assignment is to create a threaded class that "races" by counting and displaying the numbers from 1 to 10. Each of the instances of this thread class should have a unique ID (i.e. the first instance sho ...

Situation you are designing a system with a requirement to

Situation: You are designing a system with a requirement to provide direct access to 10,000 records. The data file grows at a rate of 5% per year. Evaluate the effect of a static hashed file with a load factor of .45. 1. ...

Like users computers in a domain will have an account

Like users, computers in a domain will have an account established for them. Their account can be seen in AD Users and Computers and viewed or modified there. What if you were going to add a new group of people in a new ...

Are there manufacturers and retailers who have taken steps

Are there manufacturers and retailers who have taken steps to reduce their pollution impact, both air quality and industrial pollution, while maintaining a viable place in the market?

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As