Question: Refactor the test ( ) method into a new separate thread In addition to testing the bank at the end of all the transfers, we

Refactor the test() method into a new separate thread
In addition to testing the bank at the end of all the transfers, we also want to test it periodically.
Uncomment the line in Bank.transfer that reads: if (shouldTest()) test;
Run the program again and you will notice now that the test method reports an error again.
This is because while the test method is summing the amounts in each account in one thread, transfers are still taking place in other threads. This is the source of another race condition.
To fix this race condition, you must refactor the test) method into a new separate thread
Remember that there is 1 TestThread, and there are 10 TransferThreads

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!