Question
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
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started