Task 1. Run the initial program as is to observe the race condition and explain how the race condition may occur. Draw a simple UML sequence diagram to support your explanation. Add your explanation and the sequence diagram to [login to view URL] (Links to an external site.)
You can force the race condition to be more apparent by uncommenting the [login to view URL]() statements in the Account class.
Task 2. Implement protection code to resolve the race condition issue. Your solution must allow the bank to transfer multiple funds between unrelated accounts, e.g. from account  to account  and from account  to account  at the same time. You may use either synchronized object locks or classes implementing the Lock interface to prevent two transferring threads from accessing the same global variables simultaneously.
In addition to testing the bank at the end of all the transfers, we also want to test it periodically. Uncomment the line in [login to view URL] 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. In the next tasks we will fix this.
Task 3. Refactor the method of testing into a new separate thread.
Task 4. Provide code protection so that the newly-created testing thread and any other transfer threads are running exclusively.
Now we have protected the critical sections of the code by providing mutual exclusion between the testing thread and the transfer threads. But we want to run the test at regular intervals, so we need a solution to guarantee that the test runs at the right time.
Task 5. Implement a wait/signal solution for the testing thread and transfer threads, i.e. the testing thread starts with a signal to all transferring threads, waits for all the transferring threads to finish the current transfer, and then takes over the testing task while all the transferring threads are waiting until the test is done.
Task 6. The initial code does not allow an account to transfer out funds if the transferring amount is greater than the account balance. Implement a wait/notify solution to defer the transfer until the account balance becomes greater than the transferring amount (assume the account will receive the funds later).
Task 7. Deadlock condition may occur if one thread finishes all the funds transfers and exits. Implement a solution in which all threads stop transferring (the bank is closed) whenever one thread completes its transfers. This will solve the deadlock issue.
20 freelancers are bidding on average $500 for this job
Hi, Hope you are doing well. I have full experience about Java/JavaFX so that I can handle your project perfectly. I will be very happy to discuss about your project via chatting. Thank you.