Java NIO Tutorial
|
Jakob Jenkov Last update:2014-06-25 |
Java NIO (New io) is a alternative IO API for Java (from Java 1.4), meaning alternative to the Standardjava io and Java N Etworking API ' s. Java NIO offers a different of working with IO than the standard IO API ' s.
NIO is an alternative IO API that can be used instead of the original IO and network APIs.
Java Nio:channels and buffers
The standard IO API is the streams and character streams with byte. In NIO channels and buffers. Data is all read from a channel into a buffer, or written from a buffer to a channel.
The standard IO API works with a byte stream and a character stream; NiO is working with channel channels and buffer buffers, where data is read from the channel to buffer, from buffer to channel
Java nio:non-blocking IO
NIO is a non-blocking io,thread that allows the channel to read the data to buffer, and then the thread can do other things, and after reading it can continue to deal with him.
Java NIO enables do non-blocking IO. For instance, a thread can ask a channel to read data into a buffer. While the channel reads data to the buffer, the thread can do something else. Once data is read to the buffer, the thread can then continue processing it. The same is true for writing data to channels.
Java nio:selectors
A selector can simulate processing data that operates on multiple channel.
Java NIO contains the concept of "selectors". A Selector is an object that can monitor multiple channels for events (Like:connection opened, data arrived etc). Thus, a single thread can monitor multiple channels for data.
How all this works was explained in more detail with the next text in this series-the Java NIO Overview.
Java NIO Tutorial