• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is it necessary synchronize on seek?

 
Zee Ho
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From other thread, I found that Andrew said that:

You should only synchronize on the methods that are dealing with
the physical file access


I implemented the method named seek to move the file pointer of RandomAccessFile to proper position base on the record number. does that method need to be marked as synchronized AND WHY? or we only need to sychronized the method like this (only synchronized the method physically write to file?):

 
Zee Ho
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
through reading other threads I got some idea about this topic. is it right that any method invoke the RandomAccessFile.seek/read/write MUST be marked as synchronized?
[ April 30, 2005: Message edited by: Zee Ho ]
 
Steve Taiwan
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used only one RandomAccessFile instance in my assignment since not every
OS supports many RandomAccessFile instances to read the same file. To
mark all read/write methods synchronized is because the pointer of
RandomAccessFile instance should be used only by one method at a time.
If the pointer of RandomAccessFile instance is used by more than one
methods at the same time, they could read/write wrong data when the
pointer would be moved to wrong locations by different methods.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic