This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Can i read and add records in 2 diff. instances? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Can i read and add records in 2 diff. instances?" Watch "Can i read and add records in 2 diff. instances?" New topic

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

Rajesh So
Ranch Hand

Joined: Oct 08, 2002
Posts: 148
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,
Peter den Haan
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
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:
subject: Can i read and add records in 2 diff. instances?
It's not a secret anymore!