简体   繁体   中英

Why FileChannel in Java is not non-blocking?

I wanted to write a program which writes to multiple files simultaneously; thought it will be possible with one thread by using non-blocking mode. But FileChannel does not support non-blocking mode. Does anybody know why?

UNIX does not support non-blocking I/O for files, see Non-blocking I/O with regular files . As Java should (at least try to) provide the same behaviour on all platforms, the FileChannel does not implement SelectableChannel .

However Java 7 will include a new AsynchronousFileChannel class that supports asynchronous file I/O, which is a different mechanism to non-blocking I/O.

In general only sockets and pipes truly support non-blocking I/O via select() mechanism.

简而言之,大多数操作系统不会将常规文件视为可以阻止的内容 - 因此它们不允许您将它们显式设置为非阻塞状态。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM