This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can i read and add records in 2 diff. instances?

 
Rajesh So
Ranch Hand
Posts: 149
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author
Ranch Hand
Posts: 3252
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic