I have a couple of questions regarding locking
1. Do i need to look after locking on a file access level as well as on a record level?
In the DVDDatabase example in the
SCJD Exam book ( Habibi etc ) they implement a seperate DVDDatabase instance per client - in this way I can only see that records get locked ( using a static collection as a monitor and id holder ) not access to the file. Even though all methods in DVDDatabase are syncronized there are multiple instances of DVDDatabase so 2 clients could access two different records and update the database file at the same time. I am assuming that I shouldn't be allowing concurrent writes on the database file??
3. If I implement my database access layer using the Singleton
pattern ( and making all methods synchronized ) then I can't see a need to lock individual records as only one
thread will be able to access the database at one time.
Your thoughts on the above will be appreciated.