RandomAccessFile 写入是异步的吗?

发布于 2024-12-07 12:37:49 字数 299 浏览 0 评论 0原文

查看 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

以酷 2024-12-14 12:37:49

RandomAccessFile 写入是异步的吗?

同步/异步区别是指保证在write调用返回之前数据/元数据已安全地写入磁盘。如果没有同步模式的保证,您写入的数据可能仅在 write 系统调用完成时仍在内存中。 (数据最终将被写入磁盘......通常在几秒钟内......除非操作系统崩溃或机器由于电源故障或其他原因而死机。)

同步模式输出(显然)比异步模式慢输出。

这是否意味着“rw”模式是异步的?

是的,从上面的意义上来说确实如此。

如果我需要知道文件写入何时完成,是否需要包含“s”?

是的,如果“完整”是指“写入光盘”。

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".

街角迷惘 2024-12-14 12:37:49

使用多线程时,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 a synchronous mode for read and write operations.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文