Create a new java project in eclipse


Create a new Java Project in Eclipse and complete the following requirements based on the Threads. Several threads will share a single object and contribute their individual result to the shared object. The shared object accumulates the partial results. Create a package named cs520.hw6. Using this package, create the following classes. 1. Create a class named SharedResults as follows. The class keeps track of the shared result. a. The instance (or member) private variable result (int). b. A void addToResult method which 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 the synchronization issue with this method. 2. Create a class named LongTask which 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 the loop, invoke the addToResult method of the shared object and provide this accumulated sum. 3. Create a Test class to test the following functionality in its main method. a. Create the SharedResults object and assign it to a variable. b. Create 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 created. d. Wait for all the threads to complete using the join method. e. Print the result from the shared object.

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: Create a new java project in eclipse
Reference No:- TGS096056

Expected delivery within 24 Hours