Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Confused on synchronization of RandomAccessFile  RSS feed

 
Leo Tien
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my design, every client use it's own Data class instance. In the Data class, I have a static variable of DataSchema which is singleton and another static variable which type is RandomAccessFile comes from the DataSchema class. This ensures that only one RAF to access the db file at the same time.
I think because I use mutilple Data instance, to define the methods synchronized in Data class isn't make any senses. But some methods in Data must support synchronized mechanism, e.g. read method, there are three steps in it: 1) validate the record whether is valid, if not throws RecordNotFoundException. 2) call raf.seek method. 3) call DataHelper.readFixedString method to read the data from db file.
If there isn't synchronized mechanism, can make some exceptions, pls see this thread.
What you think about this and what should I do ?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!