Why FileChannel in Java is not non-blocking?

后端 未结 2 1581
花落未央
花落未央 2020-12-24 07:34

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 s

2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-24 08:12

    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.

提交回复
热议问题