File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Mannaging concurrent access to DB File Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Mannaging concurrent access to DB File" Watch "Mannaging concurrent access to DB File" New topic
Author

Mannaging concurrent access to DB File

Itapaj� Takeguma
Ranch Hand

Joined: Jul 21, 2004
Posts: 41
I was remembering that some one said that, to support clients' access to the database, was opening a RandomAccessFile for every client (I didn't find that Topic and I'm opening this).

I though that to resolve concurrent access I just need to create kind of a pool to wrap the RandomAccessFiles. When I client needs one he asks for one, when he doesn't need, he puts it back in the pool.

The biggest problem with this solutin is when one needs to create a new record (if there are no empty slots), so the database file has to grow, and some space has to be reserved for that record in the file.

I'd like some comments from you again,
thanks,
Itapaj�.
Anton Golovin
Ranch Hand

Joined: Jul 02, 2004
Posts: 476
Originally posted by Itapaj� Takeguma:
I was remembering that some one said that, to support clients' access to the database, was opening a RandomAccessFile for every client (I didn't find that Topic and I'm opening this).

I though that to resolve concurrent access I just need to create kind of a pool to wrap the RandomAccessFiles. When I client needs one he asks for one, when he doesn't need, he puts it back in the pool.

The biggest problem with this solutin is when one needs to create a new record (if there are no empty slots), so the database file has to grow, and some space has to be reserved for that record in the file.

I'd like some comments from you again,
thanks,
Itapaj�.



My project will only have one instance of the Data class and all classes below Data. There will be one RandomAccessFile open per method call for my DBIOManager (read, write, readAll.) I am caching the database because of speed considerations. It is efficient because I will have read all the records at startup, and I will only need to read, write individual records at program run.

I don't see that they would be expecting concurrent access to the file because they are asking for record locking. If you have concurrent access to the file, it will corrupt the file. You would have to lock the file for writing when doing so. Therefore, it's like record locking, because when you lock the file, you don't need to implement higher-level record locking. Therefore I think they except you to cache the detabase.


Anton Golovin (anton.golovin@gmail.com) SCJP, SCJD, SCBCD, SCWCD, OCEJWSD, SCEA/OCMJEA [JEE certs from Sun/Oracle]
Itapaj� Takeguma
Ranch Hand

Joined: Jul 21, 2004
Posts: 41
Some people says that it isn't very good to load all your database into your memory (at least when you have a very big database). Even beeing more fast it choosed to implement directely into the database.



I don't see that they would be expecting concurrent access to the file because they are asking for record locking.


I think there's no problem with concurrent access. When a client asks to lock a record, I think the other records shouldn't be locked (I mean, they should be accessable).

If you have concurrent access to the file, it will corrupt the file


I made some tests and I think that when you open the same file more than one time and write to some instance of it, every thing is done gracefully. I think the problem is when you write to the same position in file.

thanks for your reply,
Itapaj� Takeguma

[Andrew: I have edited your post to put the code between [quote] and [/quote] UBB tags rather than [code] and [/code] tags.]
[ August 19, 2004: Message edited by: Andrew Monkhouse ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Mannaging concurrent access to DB File