欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

Java NIO,

来源: javaer 分享于  点击 16584 次 点评:100

Java NIO,


Java NIO

本文译自:http://tutorials.jenkov.com/java-nio/index.html

1.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中,你将和channels,以及buffers打交道。数据总是从一个channel读取到一个buffer中,或者从一个buffer写入到一个channel中。

2.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可以让你执行非阻塞IO。例如:一个线程能够请求一个channel去读数据到一个buffer中。当这个channel往这个buffer中读数据的时候,线程可以做一些其他的事情【这些其它的事情是哪些事情?难道还有事情是在没有取得数据就可以做的么?】。 一旦数据被读入到buffer了,线程就能够继续处理它(buffer)。将数据写入channels中也是如此的。

3.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包含“selectors”的概念。一个selector是一个对象,这个对象包含监控多个channels事件(如:连接打开,数据到达等)。那么单个线程能够为了数据而监控多个channels。

相关文章

    暂无相关文章
相关栏目:

用户点评