My question is what is the point of calling notifyAll() in the locking method? It is obvious why you need to notify after unlocking a record, but I don't understand the point of notifying after locking a record.
My guess is that the authors just wanted the DVDDatabase class to be thread-safe despite the fact that it can't be used directly, but I may be missing something?
Originally posted by Dan Murphy:
Thanks for your reply Andrew,
If I understand you correctly, then you agree that
- there is no need to call notify() after locking
- the DVDDatabase methods do not need to be synchronized
Of course, if the requirements were to change, or features were addded, these statements could become false, but it seems they are true of the code as presented in the book?
The call to notfiyall on pp. 129, line # 9, is there to assist the thread that might be waiting to lock the entire DB. This is a requirement in the SCJD version that existed when the book was written: FBN. A given client had to be able to lock the entire database.
Now for your question on the DVDDatabase methods. The methods do need to be synchronized, if you have a system set up, per figure 4-14, p. 127. The discussion on pgs. 127explores this. The following discussion, on p.128, discusses the fact that the system will work for either setup: figure 4-13 or figure 4-14. Yes, the current system in the book is set as per figure 4-13, and that's explained in the second paragraph of page 127.
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koophttps://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton