Reputation: 31493
Looking at the constructor of RandomAccessFile for the mode it says 'rws' The file is opened for reading and writing. Every change of the file's content or metadata must be written synchronously to the target device.
Does this imply that the mode 'rw' is asynchronous? Do I need to include the 's' if I need to know when the file write is complete?
Upvotes: 2
Views: 1161
Reputation: 718788
Are RandomAccessFile writes asynchronous?
The synchronous / asynchronous distinction refers to the guarantee that the data / metadata has been safely to disk before the write
call returns. Without the guarantee of synchronous mode, it is possible that the data that you wrote may still only be in memory at the point that the write
system call completes. (The data will be written to disk eventually ... typically within a few seconds ... unless the operating system crashes or the machine dies due to a power failure or some such.)
Synchronous mode output is (obviously) slower that asynchronous mode output.
Does this imply that the mode 'rw' is asynchronous?
Yes, it is, in the sense above.
Do I need to include the 's' if I need to know when the file write is complete?
Yes, if by "complete" you mean "written to disc".
Upvotes: 5
Reputation: 94645
That is true for RandomAccessFile
and java.io classes when using multiple threads. The mode "rw" offers asynchronous read/write but you can use a synchronous
mode for read and write operations.
Upvotes: 3