Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 1 Describe the scenario in which the concurrent usage of BankAccount object by two threads will result in an incorrect bank balance when the

image text in transcribed

Part 1

Describe the scenario in which the concurrent usage of BankAccount object by two threads will result in an incorrect bank balance when the threads are finished executing. Show the EXACT interleaved sequence of operations executed by the threads.

Part 2

Show how you would change the BankAccount class in order to make the thread SAFE, allowing multiple threads to run without problems.

Part 3

Explain if Part 2's thread safe class would offer enough protection against concurrently running threads (one is transferring money from one account to another, while the other is accessing one or both accounts for a withdrawal or deposit or balance check).

If so, explain how your code keeps the thread safe. If not however, explain a situation in which the balance would show an incorrect value, and provide a brief explanation on how you could fix it?

Consider the following BankAccount class: public class BankAccount \{ private float balance; public BankAccount (float money) balance = money; } public void deposit (float money) { balance = balance + money; } public void withdraw (float money) \{ If (balance >= money) balance = balance money; else throw new Exception (money + " is more than balance"); 3 public float getBalance() { return balance; } \}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Students also viewed these Databases questions

Question

Describe how language reflects, builds on, and determines context?

Answered: 1 week ago