• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question about Max's DVD Example

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
I am Arthur, King of the Britons. And this is a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic