I have a class called \"Account\"
public class Account {
public double balance = 1500;
public synchronized double withDrawFromPrivateBalance(double
Your private synchronized void find() method is synchronizing on different locks. Try synchronizing it on same objects like
private void find(){
synchronized(myTargetAccount){
localBalance = myTargetAccount.balance;
System.out.println(getName() + ": local balance = " + localBalance);
localBalance -= 100;
myTargetAccount.balance = localBalance;
}
}
You can also make your Account class more thread safe, by making its fields private and adding synchronized modifier to all its getters and setters and then use only this methods to change value of fields.