hI Animesh,
When I try to read a record...... read(recNo)....How do i know that while I am reading the record its not being updated by update method or deleted?
From the client's perspective you have at least the following two choices:
Don't worry about whether a record has been updated - just verify at the time of booking that it is still available.Have the server notify every connected client of every record that gets updated, and verify at the time of booking that the record is still available. Note that in this case you would have to either have the server keep track of which records each client is interested in so that you only notify them of the subset that they want, or you are going to have to build logic in the client to determine whether they are interested in an update.The second option is, in my opinion,
way outside of the specifications given, and it is much harder to do. So why do it?
Was that your real code you posted? If so, there may be some comments on it. But I am unsure I want to spend time commenting on conceptual code.
retrieveRecord(recNo) is a private function which gets the record from the File. (Its not synchronized)
If it is not synchronized, what is to stop two threads interferring with each other:
Thread A seeks to the location in the file where record 5 startsThread B seeks to the location in the file where record 3 startsThread A reads record 3 - that client now has the wrong dataThread B reads record 4 - that client now has the wrong dataNote that this scenario gets even worse depending on how you are doing your updates, since you could corrupt multiple records just by failing to synchronizing on the read!
By the way: Putting code between [code] and [/code]
UBB tags] helps keep the indenting, which usually makes the code easier to read and more likely for people to comment on it. If you want to see how I did this on your post, click the edit button (
) that appears in the top line of
your post (you can try clicking the same button that appears in my post, but you will just see an error message
).
Regards, Andrew
[ March 25, 2006: Message edited by: Andrew Monkhouse ]
[ March 25, 2006: Message edited by: Andrew Monkhouse ]