java NIO 基础概念

本文深入探讨了Java NIO的概念,包括通道和缓冲区的工作原理,非阻塞IO的特性,以及选择器如何帮助线程监控多个通道的数据事件,使程序员能够更高效地处理I/O操作。

译文: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包含“选择器”的概念。选择器是一个可以监视多个通道的事件的对象(比如连接打开,数据到达等等)。因此,一个线程可以监视多个通道以获取数据。

 

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

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值