Java IO

  1. Blocking IO
    There are two types IO(blocking IO) in Java.

The first one is InputStream/OutputStream, which is the super class of all classes representing an input/output stream of bytes.
Another one is Reader/Writer, which is the super class of all classes representing an input/output stream of character.

  1. Asynchronous IO
    Asynchronous IO refers to an interface where you supply a callback to an IO operation, which is invoked when the operation complete. This invocation often happens to an entirely different thread to the one that originally made the request, but this is not necessarily the case. Asynchronous IO is a manifestation of the "proactor" pattern.

  2. Non-blocking IO
    Non-blocking IO refers to an interface where IO operations will return immediately with a special error code if called when they are in a state that would otherwise cause them to block. So for example, a non-blocking recv will return immediately with a EAGAIN or EWOULDBLOCK error code if no data is available on the socket, and likewise send will return immediately with an error if the OS send buffers are full. Generally APIs providing non-blocking IO will also provide some sort of interface where you can efficiently wait for certain operations to enter a state where invoking the non-blocking IO operation will actually make some progress rather than immediately returing. APIs in this style are implementations of the reactor pattern.

comments powered by Disqus