非阻塞文件读取 [英] Non-Blocking File Reads
问题描述
在java中是否有非阻塞文件读取API?如果不是,那么在C ++中构建一个并通过JNI从一个java应用程序调用它是明智的?
Is there a non-blocking file read API in java? If not would it be wise to build one in C++ and call it from a java app via JNI?
推荐答案
否, FileChannel code>不扩展
SelectableChannel
。
No, FileChannel
does not extend SelectableChannel
.
可能是因为并非所有的操作系统都支持它。
Probably because not all OSes support it.
Windows可以,特定的C ++库,并通过JNI调用它,但它是很多工作集成这个与 java.nio
。
Windows does, and in theory you could write a windows-specific C++ library and call it via JNI, but it is a lot of work to integrate this with java.nio
.
我宁愿有一个工作线程将文件内容复制到 pipe ,并在管道的另一端进行非阻塞读取。
I would rather have a worker thread copy the file contents to a pipe and do non-blocking reads on the other end of the pipe.
这篇关于非阻塞文件读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!