Non-Blocking File Reads

My original answer is now wrong, since the addition of AsynchronousFileChannel in Java 7.

You still cannot select on a file, but there are now two asynchronous file read methods: one that takes a callback and another that returns a Future.

It may be cleaner to use the callback method (and dispatch an event from the callback) than to have a dedicated thread polling a pipe.


No, FileChannel does not extend SelectableChannel.

Probably because not all OSes support it.

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.

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.