Originally posted by joel smither:
Hi I'm working the UrlyBird developer project. I have implemented a seperate LockManager class to to the real work of locking and unlocking records. I have made these methods synchronized, because they need mutual exclusive access to some hashmaps I'm using to maintain information on which records are locked.
Is there really a need for any other methods to be synchronized? In my Data class I have methods readRecord, updateRecord, findByCriteria, etc. These methods don't have to be synchronized do they?
SCJP 1.4<br />SCJD 1.4
Originally posted by joel smither:
I'm sort of weak on terminology. I believe my Data class is a facade...it is the class that implements the methods readRecord, createRecord, deleteRecord, updateRecord, lockRecord and unlock, etc. The lockRecord and unlock methods are not synchronized in this class. So is this what u mean by facade?
My LockManager sychronizes its methods called lock and unlock. When I want to update a record, I first call the lock method in my LockManager class. Once I get the lock I then call updateRecord to actually update the record.
Why do the updateRecord and deleteRecord methods have to be synchronized in my Data class?
SCJP 1.4<br />SCJD 1.4
Originally posted by joel smither:
In the UrlyBird project there is no requirement for the end user to do a delete, as a result I've assummed this is an off-line operation that doesn't need to be synchronized.
Whenever I want to book a record (i.e. update the record) I perform a lock on it....it's the lock method in my LockManager class that is synchronized...so I still don;t understand why the update method needs to be synchronized. You have to have a lock on the record before you can update it.
so I still don;t understand why the update method needs to be synchronized.
SCJD 1.4<br />SCWCD
Originally posted by joel smither:
I think I understand what you're saying, however I still don't think I need to make any method synchronized except for lockRecord and unlock methods defined in my LockManager class.
joel smither: There's no way that 2 clients could update the same record with this scheme is there?
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.
doesn;t this mean I can't add the synchronized keyword to those methods?
SCJD 1.4<br />SCWCD
Originally posted by joel smither:
Boy, the information provided on this thread is extemely enlightening, thanks for all who responded.
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?[/QB]
If you settle for what they are giving you, you deserve what you get. Fight for this tiny ad!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|