Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Database Theory And Application Bio Science And Bio Technology International Conferences DTA And BSBT 2011 Held As Part Of The Future Generation In Computer And Information Science 258

Authors: Tai-hoon Kim ,Hojjat Adeli ,Alfredo Cuzzocrea ,Tughrul Arslan ,Yanchun Zhang ,Jianhua Ma ,Kyo-il Chung ,Siti Mariyam ,Xiaofeng Song

2011th Edition

ISBN: 3642271561, 978-3642271564

More Books

Students also viewed these Databases questions

Question

Given a matrix, A = 41 , find (4A) 19 140 140 16 36 140 35 4 16

Answered: 1 week ago