Hi, I tried to read/find records in one instance of a file and adding/modifying/deleting in another instance of the same file. There were no errors or exceptions. For example,
forRead instance can be used for read/find records. forWrite instance can be used for add/delete/modify records. Both were running parallely and did not give any exceptions. But is this a right way of doing? If yes, only 'forWrite' should have one instance and made synchronous. Please tell me if I am right. Thanks in advance, Rajesh
Peter den Haan
posted 14 years ago
If memory serves, you can actually get two or more RandomAccessFile objects to work consistently against one single file. This critically depends on them sharing the same buffer, and I cannot remember how documented this actually was. Should you want to do this kind of thing, then I'd strongly encourage using the new I/O package over using a RandomAccessFile. File channels are safe against multithreaded access, and by mapping the database file to memory you can probably keep things relatively simple and highly concurrent. Relatively simple. Please note that (unless they've been changed since I did the test) the instructions explicitly require that you do not complicate the design for performance reasons. The original Data you've been given caters for multiple requests by simply synchronisation, effectively serializing any file I/O. My understanding of the requirements was, and still is, that you are supposed to keep it that way. - Peter
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads