Search code examples
javarx-javaspring-webfluxproject-reactornonblocking

Read file line by line using non-blocking IO with reactive wrapper in Java


Is there any way to read a local file line by line without blocking any thread (background thread pool counts as blocking) using built-in CompletableFuture or a reactive stream library like RxJava or Reactor?

(It's interesting that there are many non-blocking IO libraries for HTTP and different databases like Mongo, Redis, etc., but I wasn't able to find anything for a simple file read.)


Solution

  • There are similar questions:

    The main reason why Java has no universal non-blocking file IO is the following: Java is a cross-platform language, but Unix does not have non-blocking access to files.

    If you program for Windows, there is a platform-specific implementation WindowsAsynchronousFileChannelImpl, that uses a non-blocking mechanism.