Hi,
I'm just starting with threads, using Head First
Java. I tried to code the Ryan and Monica example (Ryan and Monica both withdraw $10 at a time from their joint bank account...) and everything went swimmingly until I tried to put in a synchronized block to avoid overdrafts. If this works correctly, the total amount withdrawn should always be $100 (which is also true if I put the Thread.sleep() in a more reasonable location, but I'm doing this to figure out how threads work). However, in the code below, $110 gets withdrawn about 20% of the time on my machine.
What am I doing wrong?
Thank you!! Karen.