• Post Reply Bookmark Topic Watch Topic
  • New Topic

mistake in andrew's book

 
Maksym Odintsov
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!