Java – IO @ Blocking vs. Non-blocking

Various streams are blocking in Java IO’s. Usually, when a thread invokes a read() or write() operation, that thread is blocked until there is some data to read, or the data is fully written. This results that respective thread cannot do anything in the meantime.

Java NIO’s non-blocking mode enables a thread to request reading data from a channel, and only get what is currently available, or nothing at all, if no data is currently available. Instead of remaining blocked until data becomes available for reading, the thread can go further with something else. This is true for non-blocking writing wherein a thread can request that some data be written to a channel, but not wait for it to be fully written.

What threads spend their idle time on when not blocked in IO calls, is usually performing IO on other channels in the meantime. That is, a single thread can now manage multiple channels of input and output.

!! Happy Revision/Learning !!