• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: static RandomAccessFile?

 
Jim DiCesare
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my original design I only locked records, which restricted access to the database file, so you can only write to your part. Recently, I've read some posts mentioning that file location pointers might get messed up between threads, and that I need to synchronize file access. If I want to synchronize on RandomAccessFile does it have to be a static object so that I can lock all threads until I close the file?
I know there are multiple threads grabbing instances of my remote class, but when multiple threads act on the servers data class, do they each get an instance, or do all threads work off of the same instance. If they work off the same instance I wouldn't necessarily need to make my RandomAccessFile static.
 
Jason Mowat
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jim,
I implemented the ReadWriteLocking pattern [Grand] in my RandomAccessFile. My main concern was that the program uses database length to determine offsets of the records, and that if multiple clients were to add records simultaenously, there could be a problem with reads or writes of other clients. It seems to work pretty well.
The idea for this has come from the book "Patterns in Java Volume 1", by Mark Grand. If there is are write operations, all pending reads will wait until the writes are done. However, if there are only reads, they are all allowed to execute simultaneously, if necessary. It's essentially a tread management class, but it was quite helpful.
Hope that helps!
Cheers,
Jason
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic