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
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
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
SCJP, SCJD, SCWCD, SCBCD
I am Arthur, King of the Britons. And this is a tiny ad:
a bit of art, as a gift, the permaculture playing cards