The problem is in the thread handling in Java, if you withdraw befor you add then withdraw again, it is going to be different than add, withdraw, add.
It all depends on how the threads lock the program from any inteference from other threads performing actions uppon the total ammount.
Thats why you need to try different aproaches ie:
Quote:
part 1:
Use Java Synchronization to avoid the race condition presented in the code.
part 2:
Use semaphore approach for this problem.
part 3:
Modify the code so that only one payroll thread and one withdraw thread are launched.
Then use Peterson's solution for mutual exclusion between the payroll and withdraw threads
|
What Bel is trying to tell you is this, figure it out by looking at how Java handles threads in teh ways you need to test it. (part 1, 2, 3)