Objectivesthis is an introductory assignment on java

Assignment Help JAVA Programming
Reference no: EM13353404

Objectives

This is an introductory assignment on Java synchronization. You will use Java Threads while learning more about concurrency and achieving atomicity using Java’s inbuilt mechanisms.

Source Code

There are four files provided with the assignment. You will need these files to work on the assignment.

The files are available in the zip file 1.zip.

File Checklist

Account.java

AccountManager.java

Depositor.java

Withdrawer.java

Background

In this assignment, you will deal with concurrent executions of multiple threads operating on a shared data structure (Accounts). You will be learning more about Java threads and synchronization mechanisms as you work on this assignment.

An array of accounts holds 10 accounts information (imagine an OS shared resource of the same type).

The account array has a valid state once it is initialized. You will employ 10 threads for deposit and 10 threads for withdrawal; each thread is bound to a specific account. There will be one depositor thread and one withdrawer thread that are bound to one

specific account. The depositor is responsible for depositing X amount to the account and the withdrawer is responsible for withdrawing the same X amount from the same account. As a result of running 20 threads the final accounts’ balance/state should be the same as initial accounts’ balance/state. The main goal is to maintain the accounts’ state valid regardless of the number of the concurrent threads accessing them, and regardless of their order.

A snapshot of a consistent run:

Print initial account balances

Account: 1234 Name: Mike Balance: 1000.0

Account: 2345 Name: Adam Balance: 2000.0

Account: 3456 Name: Linda Balance: 3000.0

Account: 4567 Name: John Balance: 4000.0

Account: 5678 Name: Rami Balance: 5000.0

Account: 6789 Name: Lee Balance: 6000.0

Account: 7890 Name: Tom Balance: 7000.0

Account: 8901 Name: Lisa Balance: 8000.0

Account: 9012 Name: Sam Balance: 9000.0

Account: 4321 Name: Ted Balance: 10000.0

Depositor and Withdrawal threads have been created

Print final account balances after all the child thread

terminated...

Account: 1234 Name: Mike Balance: 1000.0

Account: 2345 Name: Adam Balance: 2000.0

Account: 3456 Name: Linda Balance: 3000.0

Account: 4567 Name: John Balance: 4000.0

Account: 5678 Name: Rami Balance: 5000.0

Account: 6789 Name: Lee Balance: 6000.0

Account: 7890 Name: Tom Balance: 7000.0

Account: 8901 Name: Lisa Balance: 8000.0

Account: 9012 Name: Sam Balance: 9000.0

Account: 4321 Name: Ted Balance: 10000.0

Elapsed time in milliseconds 13900

Elapsed time in seconds is 13.9

A snapshot of an inconsistent run:

Print initial account balances

Account: 1234 Name: Mike Balance: 1000.0

Account: 2345 Name: Adam Balance: 2000.0

Account: 3456 Name: Linda Balance: 3000.0

Account: 4567 Name: John Balance: 4000.0

Account: 5678 Name: Rami Balance: 5000.0

Account: 6789 Name: Lee Balance: 6000.0

Account: 7890 Name: Tom Balance: 7000.0

Account: 8901 Name: Lisa Balance: 8000.0

Account: 9012 Name: Sam Balance: 9000.0

Account: 4321 Name: Ted Balance: 10000.0

Depositor and Withdrawal threads have been created

Print final account balances after all the child thread

terminated...

Account: 1234 Name: Mike Balance: -9180.0

Account: 2345 Name: Adam Balance: 2000.0

Account: 3456 Name: Linda Balance: -9.953971E7

Account: 4567 Name: John Balance: 1.00004E8

Account: 5678 Name: Rami Balance: -3.682011E7

Account: 6789 Name: Lee Balance: 6000.0

Account: 7890 Name: Tom Balance: -6.951315E7

Account: 8901 Name: Lisa Balance: -9.087615E7

Account: 9012 Name: Sam Balance: 1.00009E8

Account: 4321 Name: Ted Balance: -9.631527E7

Elapsed time in milliseconds 139

Elapsed time in seconds is 0.139

There are 20 threads accessing the accounts concurrently. One depositor threads

deposits into account #

1234 the amount 10 CAD in 10000000 iterations. On the other side, one withdrawer

thread withdraws

from account # 1234 the same amount 10 CAD in 10000000 iterations. The rest 9

depositor threads and 9

withdrawer threads perform the same operations over the other 9 accounts. As part of this assignment, you are required to perform the following tasks:

Task 1: Atomicity violation

Compile and run the Java app given to you as it is. Explain why the main requirement above (i.e. consistent state of the account array) is not met. Find the bug(s) that cause(s) it and in a few sentences explain how it can be fixed.

Task 2: Starting Order

Explain in a few sentences what determines the starting order of the threads. Can the consistency of the accounts preserved by changing the starting order? Explain.

Task 3: Critical section

Identify the critical sections of the given code. You can “cut and paste” the relevant pieces of code to your answer.

Task 4: Method level synchronization

Create a package named Task4 and copy the provided java files into the new package. Use Java’s method level synchronization mechanisms to provide a solution to the inconsistency problem at hand.

Task 5: Block level synchronization (also known as: Synchronized statements) Create a package named Task5 and then copy the java files from Task 4 into the new package. This time, use Java’s block level synchronization (synchronized statements) mechanisms to provide a solution to the inconsistency problem at hand.

Task 6: Synchronized block versus synchronized method Considering the results of Task 4 and Task 5, what is(are) the advantage(s) of synchronized block over synchronized method, or vice versa? Explain. Possible file layout:

PA1.txt -- Written components for Tasks 1, 2, 3, and 6

Task4:

*.java -- Fixed Java code

before.out -- Buggy output

after.out -- Output after the code has been fixed

Task5:

*.java -- Fixed Java code

after.out -- Output after the code has been fixed according to Task 5

Reference no: EM13353404

Questions Cloud

Q the article critique is based on the following : q. the article critique is based on the following articlemundy r. d. 2003 december. the safety man cometh. professional
Question on 4 different graphs illustrate what happens to : question on 4 different graphs illustrate what happens to equilibrium price and quantity in the market for orange juice
Question from the informations given below you are required : question from the informations given below you are required to prepare a projected balancenbspsheet profit and loss
This project is to develop a program that implements a : this project is to develop a program that implements a hierarchical jpeg encoderdecoder for greyscale images.write your
Objectivesthis is an introductory assignment on java : objectivesthis is an introductory assignment on java synchronization. you will use java threads while learning more
Your company is thinking about acquiring another : your company is thinking about acquiring another corporation. you have two choicesmdashthe cost of each choice is
Create and run the followingnbspsqlnbspqueries and submit : create and run the followingnbspsqlnbspqueries and submit the screen shot of your result. also submit the file
Youve just been hired onto abc company as the corporate : youve just been hired onto abc company as the corporate controller. abc company is a manufacturing firm that
Q a producer and customer agree to transact 10000 widgets : q. a producer and customer agree to transact 10000 widgets per day and they will jointly inspect 120 widgets randomly

Reviews

Write a Review

JAVA Programming Questions & Answers

  Balanced and competitive business practices

The United States has several laws that are intended to further fair, balanced, and competitive business practices. Do you think that such laws are effective? If so, why? If not, why not? Be sure to provide evidence to support your position one way o..

  Qr codes are a popular way

QR codes are a popular way to encode data for easy reading by computerized cameras. True QR codes contain error correction, format specifiers, version information, and a size variable layout that makes them harder to decode and process

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Chat monitoring system

The name of the project is chat monitoring system. in the file you will see the screenshot diagram 2A are my design, i want it to be upgrade, to look professional like the diagram 2B. please java, netbeans and GUI. please can I have only the client s..

  Java code that needs to be coded-complex number class

Just a Java Code that needs to be coded. Your given the design, just needs the methods and such to be fixed. This is for a Complex Number class.

  Correct example of inheritance

Which of the following relationships is not a correct example of inheritance?  Parent to Children  Aunt to Uncle  Grandparent to Grandchild

  Determine the visual resolution of resulting image

Drawing in 8.5 by 11 inch sheet is digitized by means of 300 dpi (dots per inch) scanner. Determine the visual resolution of resulting image (number of dots in each dimension)?

  Client class to test implementation of the vector class

Write a client class to test your implementation of the Vector3D class thatyou implemented. Name the package in which this class is defined (projectname) vector3dapp.

  Powerful pain reliever are consumers with headaches

Your target market for the most powerful pain reliever are consumers with HEADACHES. Start with goals and objectives. Do a SWOT. What information is most important for your market? Do some market research.

  Create a project in eclipse

Create a new project

  Computing the time complexity using the big-o notation

You are required to calculate the time complexity using the big-O notation of the Algorithm_2 given by the following methods defined by the following Java code.

  Your letterinventory class must use an array

Your LetterInventory class must use an array of Counter objects. Note that there is no nextChar method in the Scanner class. You must use the next() method and then use a loop through the characters of the token that is returned. Ignore any character..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd