Jim, Thanks for your help.
a. the search result is the correct result.
I understand what you said I can never be able to return the really correct result even if I lock all file. However I am think if I do not lock all records, I might have to filter out some error records.
For example, if a user search for a name of "Tom", and find() method gives that record No.2 is "Tom", but meanwhile another client changed No.2 to another name "Mark" before my calling read(2). So after that my read of record No.2 will contain wrong information("Mark"), and I do not want to return such wrong record to the original user, so I have to do a creatia check in search()again? That seems rather wasting.
b. the find() method is based on the db file.
it's simplest to simply cache everything, rather than caching only some things, and performing different operations depending on whether a record is in the cache or not.
To solve the problem in a. I also want to cache all the records in some collection like Vector, but then I noticed I have to change the method of find(). Since now find() will be operated on a Vector instead of a real external file. I know it is still based on the db file, but it is
indirectly and I am worried about whether this is a bad thing to do. Since it seems to me that all the interface methods Sun give us should be operated on the real db file, not on a collection, isn't it true?
Please give me some direction. Thanks again.