wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes mistake in andrew's book Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "mistake in andrew Watch "mistake in andrew New topic
Author

mistake in andrew's book

Maksym Odintsov
Greenhorn

Joined: Jan 22, 2009
Posts: 11
Page 117 deadlock example.

public void run() {
String name = Thread.currentThread().getName();
synchronized (lock1) {
System.out.println(name + ": locked " + lockA);
delay(name);
System.out.println(name + ": trying to get " + lockB);
synchronized (lock2) {
System.out.println(name + ": locked " + lockB);
}
}
I think you meant lockA and lockB intead of lock1 and lock2 inside of synchronized. I tested this example and it doesn't work unless the locks are changed.
P.S Thank you for the book, it's really helping.
 
Consider Paul's rocket mass heater.
 
subject: mistake in andrew's book