This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: mistake in andrew's book
 
Similar Threads
Avoiding deadlock situations in java
wait() releases all locks?
Wait question from K&B threads chapter
Found problem in 1.5 book example
Misprint in Andrw's Book