aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes RAF pool Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "RAF pool" Watch "RAF pool" New topic
Author

RAF pool

Greg Molens
Greenhorn

Joined: Sep 20, 2010
Posts: 4
Hi,

This is my first post here, hence at the very beginig I'd like to say hallo to everyone!

Ok, here comes my concern. I am designing a solution for the Bodgitt project and decided to use a pool of RandomAccessFile instances, to achive concurrent reading and exclusive writting to a database file (ReadWriteLock will be used in order to synchronize different threads). My questions is, if I call the write() method on one RAF instance from the pool, how can I assure, that other RAF instances will actually "see" updated data immediately after the write ends? Since there is no flush() method defined in RandomAccessFile class, do I have to call FlieDescriptor's synch() method, each and every time the write operation is performed? Would this be enough solution?

Thanks in advance - G.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5201
    
  12

I would think a RAF pool is a bit complex for this assignment. Don't forget a junior programmer should be able to understand your program and make changes to it. As far as I know you are the 1st one to (try to) implement a pool of RAFs.
Why in the 1st place would you use such a pool? What's the big benefit in this approach?


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Greg Molens
Greenhorn

Joined: Sep 20, 2010
Posts: 4
Basically, it would give me controll over the number of opened FileDescriptors, which otherwise could unpredictably increase, whilst more and more clients come. Moreover I would not have to open db file, each and every time read operation occurs, if I considered concurrent reads allowed.
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2264
    
    3

Howdy, Greg. Welcome to our JavaRanch!

Champion, I agree with my good buddy Roel: instead of making things easier, you would unnecessarily introduce complexity in your assignment. It is never said in the assignment that you need to have such a thing, and remember that the key to succeed in this certification is to keep things as simple as possible.

Another approach you may have to avoid such complexity is to have a record cache, which is populated when the application is started. These records are written back to the database when the application finishes (this is the approach Roel and I applied). Also, I would say that you could probably lose points with this approach, because you would introduce more complexity than needed, and even more points if you don't do it correctly.


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RAF pool