非阻塞文件读取 [英] Non-Blocking File Reads

查看:191
本文介绍了非阻塞文件读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆