aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Is it necessary synchronize on seek? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Is it necessary synchronize on seek?" Watch "Is it necessary synchronize on seek?" New topic
Author

Is it necessary synchronize on seek?

Zee Ho
Ranch Hand

Joined: Jul 20, 2004
Posts: 128
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?):



SCJP 1.4<br />SCWCD 1.3<br />SCJD<br />SCBCD<br />IBM Xml Cert in progress
Zee Ho
Ranch Hand

Joined: Jul 20, 2004
Posts: 128
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

Joined: Jul 01, 2003
Posts: 166
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.


Steve Taiwan<br />SCJP 1.2, SCJD 1.4, SCWCD 1.3, SCBCD 1.3, OCP 8i DBA, SCEA
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is it necessary synchronize on seek?