NIO API's were introduced in Java 1.4 and had since been used for wide number of applications. NIO API's allows IO non-blocking operations.
nio api在java 1.4 开始引用,也已经在很多应用被广泛的使用了。使用nio 可以实现io无阴塞操作。
First of all, it's good to know that MINA is written on top of NIO 1. A new version has been designed in Java 7, NIO-2, we don't yet benefit from the added features this version is carrying.
目录mina 是基于nio1 实现的。一个新版本基本java7的nio2已经被设计中。
It's also important to know that the N in NIO means New, but we will use the Non-Blocking term in many places. NIO-2 should be seen as a New New I/O...
我们都知道nio意思是新的io ,我们许许多的地方要用到”非阻塞“。nio2将被看做新新io
The java.nio.*
package contains following key constructs
- Buffers - Data Containers
- Chartsets - Containers translators for bytes and Unicode
- Channels - represents connections to entities capable of I/O operations
- Selectors - provide selectable, multiplexed non-blocking IO
- Regexps - provide provide some tools to manipulate regular expressions
java nio包中下面几个部分组成
buffers --数据容器
chartsets---总于用字符编码转换
channels --io通道
Selectors ---选择多路复用的的非阻塞io
Regexps --提供一些工具操作正则表达式
We are mostly interested in the Channels, _ Selectors_ and Buffers parts in the MINA framework, except that we want to hide those elements to the user.
我主要介绍 channels ,selectors buffer 部分在mina框架中,除了我们想隐藏这些元素。
This user guide will thus focus on everything built on top of those internal components.
用户向导焦点基于上面这些组件上。
It's important to understand the difference between those two APIs. BIO, or Blocking IO, relies on plain sockets used in a blocking mode : when you read, write or do whatever operation on a socket, the called operation will blcok the caller until the operation is completed
这是很重要的了两者之间的区别 。(阻塞 io),被用于阻塞模式:当你通过io读,写或者做一些其它的操作,我们调用这个操作将会阻塞io直到这个操作完成。
This is also where NIO offers a better way to handle IO when you have numerous connected sockets:you dn't have to create a specific thread for each connection, you can just use a few threads to do the same job.
nio为你提供更好的方法。当你需要大量的io操作时,你不需要为一个为每个操作创建一个线程连接你仅仅需要很少的线程就可以完成这些工作。