Boy, the information provided on this thread is extemely enlightening, thanks for all who responded.
I want to make sure my locking is done correctly, so please forgive me if I appear to be rehashing some things...
I'm using RMI for networking. I have a Data class that implements readRecord, updateRecord, createRecord etc. Note that none of these methods are synchronized. The Data class implements my data layer so to speak. My Data class also has a LockManager. This class provides two methods, lockRecord and unlock ( which are synchronized methods).
In my client GUI, when the user wants to book a record (i.e. book a room) I first call my Data class (it has a lockRecord and unlock method as well). The lockRecord method in my Data class calls the LockManager method lockRecord to actually lock the record. Since my LockManager's lockRecord method is synchronized, only 1 client at a time can lock a record. Once I have the lock I call the updateRecord method in my Data class to update the record. Then I call my LockManager's unlock method to unlock the record. Doesn't this sequence of events ensure mutual exclusive access to that record? There's no way that 2 clients could update the same record with this scheme is there?
My second question is this: on a previous reply it was mentioned that I need to ensure access to my RandomAccessFile properly. In other words, one client could seek to record 5 while another could seek to record 10....all hell could break loose then...one client actually gets record 10 expecting record 5...
When I implemented the methods in my Data class, my filePointer variable is initialized once at start up (when I first open the file I read all the records in it and set the file pointer) and never modified again. From that point on the file pointer is just used as an offset to the appropriate record. So I'm thinking that my methods to fetch records are essentially thread safe. Is this correct or am I all screwed up here?
Also, Sun has instruction that state that I can;t change the DBAccess interface that the Data class implements, doesn;t this mean I can't add the synchronized keyword to those methods?