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?):
SCJP 1.4<br />SCWCD 1.3<br />SCJD<br />SCBCD<br />IBM Xml Cert in progress
Joined: Jul 20, 2004
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 ]
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.