[英]What is the diff between Java FileChannel.force() and StandardOpenOption.Sync?
I'm not sure if the new Java 7 nio.file.StandardOpenOption is different from the old FileChannel.force() method. 我不确定新的Java 7 nio.file.StandardOpenOption是否与旧的FileChannel.force()方法不同。
Is there a way to do O_DIRECT also? 有没有办法做O_DIRECT?
it is not possible to do O_DIRECT IO using the JVM. 无法使用JVM进行O_DIRECT IO。 One of the reasons (I think) is, that the memory where the file contents go need to be aligned to some 512 bytes boundaries.
原因之一(我认为)是文件内容所在的内存需要与512字节边界对齐。 Memory allocated with
ByteBuffers
don't fulfill this property. 用
ByteBuffers
分配的内存不满足此属性。
Another problem which is similar to this 512 bytes alignment is that you can only perform IO operations that are multiples of 512 bytes. 与此512字节对齐类似的另一个问题是,您只能执行512字节倍数的IO操作。 So if you want to read a file that has 700 bytes, you'll have troubles.
因此,如果您想读取一个700字节的文件,将会遇到麻烦。
Here is a similar thread that presents these issues. 这是介绍这些问题的类似话题。 I described a way in my blog how to implement direct IO into the JVM .
我在博客中描述了一种如何将直接IO实现到JVM中的方法 。 It also contains a hint how you could add a O_DIRECT option to the
StandardOpenOption
class (you have to add the constant to the file /src/solaris/native/sun/nio/fs/genUnixConstants.c
in the JDK sources) 它还暗示了如何向
StandardOpenOption
类添加O_DIRECT选项(必须在JDK源代码/src/solaris/native/sun/nio/fs/genUnixConstants.c
常量添加到文件/src/solaris/native/sun/nio/fs/genUnixConstants.c
中)。
I think the difference between the two is that StandardOpenOption
does it automatically while you have to call FileChannel.force()
to send the data to the underlying storage device. 我认为两者之间的区别在于
StandardOpenOption
是自动执行的,而您必须调用FileChannel.force()
将数据发送到基础存储设备。 I'm not sure about O_DIRECT. 我不确定O_DIRECT。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.