RandomAccessFile 写入是异步的吗?
查看 RandomAccessFile 对于它说“rws”的模式 文件打开以进行读写。文件内容或元数据的每次更改都必须同步写入目标设备。
这是否意味着“rw”模式是异步的?如果我需要知道文件写入何时完成,是否需要包含“s”?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
同步/异步区别是指保证在
write
调用返回之前数据/元数据已安全地写入磁盘。如果没有同步模式的保证,您写入的数据可能仅在write
系统调用完成时仍在内存中。 (数据最终将被写入磁盘......通常在几秒钟内......除非操作系统崩溃或机器由于电源故障或其他原因而死机。)同步模式输出(显然)比异步模式慢输出。
是的,从上面的意义上来说确实如此。
是的,如果“完整”是指“写入光盘”。
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 thewrite
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.
Yes, it is, in the sense above.
Yes, if by "complete" you mean "written to disc".
使用多线程时,
RandomAccessFile
和 java.io 类也是如此。 “rw”模式提供异步读/写,但您可以使用同步
模式进行读和写操作。That is true for
RandomAccessFile
and java.io classes when using multiple threads. The mode "rw" offers asynchronous read/write but you can use asynchronous
mode for read and write operations.