Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please do all the questions! 20 Points Consider the following BankAccount class: public class BankAccount { private float balance; public BankAccount (float money) { balance
Please do all the questions!
20 Points 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; p public void withdraw (float money) throws Exception \{ if (balance >= money) balance = balance money; else throw new Exception (money + public float getBalance () { return balance; } 8 Points Detail one scenario in which concurrent use of a BankAccount object by two threads results in an incorrect bank balance when the threads are done executing. Show the exact interleaved sequence of operations executed by the threads. No partial credit - either the scenario is correct, or it isn't. Enter your answer here Q6.2 4 Points Show how you would modify the BankAccount class to make it thread safe, i.e. multiple threads can concurrently access an instance without the above problem. Keep in mind that you should not overdo it by forcing unnecessary sequentiality among concurrent threads. 8 Points Would your thread safe class of 6.2 above offer sufficient protection against concurrently running threads, one of which is transferring money from one account to another, and another is accessing one or both accounts for withdrawal or deposit or balance check? If so, describe how thread safety is ensured. If not, outline a scenario in which the balance shown is incorrect, and briefly explain how it could be corrected (no need to write code for the fix, a clear and concise explanation will do). No partial credit. Enter your answer hereStep 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