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.:- M9133779

Have any Question?


Related Questions in Computer Engineering

The of the steering wheel is used to create a parallel

The _____ of the steering wheel is used to create a parallel plane in the Synchronous Part environment. The _____ option is used to apply the crown by defining its radius and take-off angle. 1-In the Ordered Part environ ...

1 what do we mean by financial intelligence how to assess a

1. What do we mean by financial intelligence? How to assess a company's health? 2. Use the plain language to define operating experience, capital expenditure, accruals, depreciation, and goodwill. 3. Describe differences ...

Question discuss in your own words using 250 words or more

Question: Discuss, in your own words using 250 words or more, the relationship between users and roles in databases. Explain why we use roles rather than simply assigning rights and privileges to each individual user. Th ...

Hemophilia is a hereditary disease for females it is known

Hemophilia is a hereditary disease for females. It is known that any female has 40% chance of being a carrier of hemophilia. If the mother was a carrier, then any daughter of hers has 50% chance of inheriting this diseas ...

Can someone show me a working implementation in c source

Can someone show me a working implementation, in C source code, of a Linux shell that will use shared memory for command execution using pipes that read data from the shared memory region? For example: you type ls -1 | w ...

Assume the following for the town of boone it has a total

Assume the following for the town of Boone: it has a total population of 40,000 people, of which 1,000 are under 16 years of age or are institutionalized; 8,000 are full-time students who are not employed and are not see ...

Systems analysis project personal trainer inc owns and

Systems Analysis project Personal Trainer, Inc. owns and operates fitness centers in a dozen Midwestern cities. The centers have done well, and the company is planning an international expansion by opening a new "superce ...

Question need to summarize 2 articles on banking data

Question: Need to summarize 2 Articles on Banking DATA Breach (2 pg per article) - Provided Need 2 Implementations on those articles (2 implementation per article & 2 page for each implementation) - How can it be improve ...

1 write code in the method linearsearch in

1. Write code in the method linearSearch() in "SearchMethods"class which finds the element in an array using linear search approach and returns its index to the calling main method, otherwise it returns -1. 2. Write code ...

Use the information on the market for bicycles to answer

Use the information on the market for bicycles to answer the following questions. Demand: P = -125*Q + 540; Supply: P = 150*Q + 210, where P is the price of bicycle and Q is the quantity demanded or supplied of bicycle. ...

  • 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