Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about Max's DVD Example

 
Jianhua Ren
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Max's DVD example, an instance of DVDDatabaseImpl is registered in the registry, so the reference of that instance could be used by multi request threads. But why the methods inside DVDDatabaseImpl such as rent(), returnRental() are not synchronized?
DVDDatabaseImpl contains one instance of DVDAdapter, same thing, methods inside DVDAdapter are not synchronized. I think the methods should be synchronized either inside DVDDatabaseImpl or inside DVDAdapter, am I wrong or right?
Thanks,
Jianhua
 
Jianhua Ren
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I know the answer now. Since in DVDAdapter class, each method calls reserveDVD()(same to our lock() method) first, it guanrantees thread safety, no need to synchronize the mothod. Correct me if I am wrong.
Thanks,
Jianhua
 
Terry Martinson
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is my understanding also. A couple good pages I keep referring to in the Max book are:
p. 176 - the final bullet point regarding locking strategy working properly
p. 317 - the last paragraph before "The Choice Between RMI and Sockets". This paragraph starts with "Chapter 4 also implemented a thread locking....".
These references just give a little background to what you explained.
TJ
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic