-
Notifications
You must be signed in to change notification settings - Fork 388
Open
Description
Issue Description:
I've noticed a small bug in the current code. Occasionally, the sequence breaks, allowing two customers to check their balance at the same time.
Proposed Fix:
To resolve this, I implemented the following fix:
public void useATM() {
synchronized(atm) {
atm.checkBalance(name);
atm.withdraw(name, amount);
}
}By using a synchronized block and locking on the "atm" reference in the Customer class, this ensures that each customer can only use the ATM object once the previous customer has finished. This change guarantees that the operations are performed sequentially, preventing any overlap.
Outcome:
After applying this fix, the sequence integrity is maintained, and no two customers can check their balance simultaneously.
Also thank you for the course, i have been learning a lot! 😄
Metadata
Metadata
Assignees
Labels
No labels