• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Is it necessary synchronize on seek?

 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic