I have a class called \"Account\"
public class Account {
public double balance = 1500;
public synchronized double withDrawFromPrivateBalance(double
Marking a method synchronized obtains a lock on the object that the method is being run on, but there are two different objects here: the ATMThread
and the Account
.
In any event, the two different ATMThread
s are using different locks, so their writes can overlap and conflict with one another.
Instead, you should have both ATMThread
s synchronize on the same object.