Hi Anthony!
The only job of the "recordNumbersLock" is to protect the recordNumbers-Hashmap from concurrent access. Every access to this object should be done over this lock. That has nothing to do with access to the RandomAccessFile "database". It should be protected too, which happens by sorrounding it with a synchronized block.
There are many ways to fullfill the requirement to program a thread-safe application. One way to make a method (that writes data to what object ever) thread-safe is to mark the hole method as synchronized.
Another way can be to synchronize as less code as possible by using locks and synchronized-blocks very sparely and carefully. And only there where it is needed. No code that does not need to be protected from concurrent access should be protected. I think this was the approach of the sample application in the book. Your are free in your choice if you use synchronized or locks, it depends on how much you are familiar with them. So, the code sample in the book represents the choice of the author.
BTW if you're programming close to the book
you should be aware of the persistDvd() method which seems not to be thread-safe as you can see here
Thread-1 and here
Thread-2. While the removeDvd() method is thread-safe, the persistDvd() is probably not. Solutions are mentioned here
Thread-3
Kind regards
Bernd
PS. Perhaps we should invite Roel here, i'm not sure but i think he marked every method in his Data class as synchronized... Roel, did you?