aspose file tools
The moose likes Java in General and the fly likes Synchronous write to same file using different file pointers Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Synchronous write to same file using different file pointers" Watch "Synchronous write to same file using different file pointers" New topic
Author

Synchronous write to same file using different file pointers

Alexander Duenisch
Greenhorn

Joined: May 29, 2006
Posts: 24
Hi ranchers,

i have written a piece of code like the following:




This function is being called by multiple threads.
Let's assume it can be guaranteed by the choice of value for location
and the length of array 'stuff', that one thread doesn't
overwrite the bytes written by another thread.

Because the RandomAccessFile is local to the method,
each thread would create it's own instance and use the associated
file pointer.

Can this be done safely or do i have to put the call to write in a
synchronized block?
In other words:
Can two or mor threads write synchronously to different locations of
the same file using different RandomAccessFile objects and thus
different file pointers, if there is no risk of one thread overwriting
another's data?

Thanks in advance for your answers.

Alex D.


---------------------------<br />OCUP-F, SCJP 5.0, SCJD, SCWCD
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35258
    
    7
I would have assumed that it's not even possible to have two file handles that perform simultaneous write operations, but I'm no expert on file systems.


Android appsImageJ pluginsJava web charts
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Synchronous write to same file using different file pointers
 
Similar Threads
Do we need synchroniation with Singleton Data class
does find(String[] criterion) need to be synchronized ?
RAF Threadsafe?
NX: static RandomAccessFile?
locking and others