java NIO 基础概念

译文:Java NIO Tutorial

源自:http://tutorials.jenkov.com/java-nio/index.html

Java NIO: Channels and Buffers

In the standard IO API you work with byte streams and character streams. In NIO you work with channels and buffers. Data is always read from a channel into a buffer, or written from a buffer to a channel.

在IO api里面,你使用字节流和字符流。在NIO,你使用通道和缓冲区,往往从通道读数据放到缓冲区里面,或者从缓冲区写入到通道中。

Java NIO: Non-blocking IO

Java NIO enables you to do non-blocking IO. For instance, a thread can ask a channel to read data into a buffer. While the channel reads data into the buffer, the thread can do something else. Once data is read into the buffer, the thread can then continue processing it. The same is true for writing data to channels.

Java NIO 不阻塞。比如,当一个线程从通道请求数据放入到缓冲区的时候,它还可以做其他的事情。一旦数据被读取到缓冲区中,线程就可以继续处理。向通道写入数据也是如此。

Java NIO: Selectors

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.

Java NIO包含“选择器”的概念。选择器是一个可以监视多个通道的事件的对象(比如连接打开,数据到达等等)。因此,一个线程可以监视多个通道以获取数据。

 

--如有表述不恰当之处,欢迎道友指正。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章