Linux系统中的IO操作内部相当复杂,下面是一张带图片的LinuxIO相关层级关系:
下面是一个简化版本Linux内部IO层级图:
对此我的理解,java程序员版本的IO理解:
从最早bio的只支持阻塞的bio(同步阻塞)
到默认阻塞支持非阻塞nio(同步非阻塞+同步阻塞)
再到aio(异步非阻塞)
示例代码: socket https://github.com/victorsheng/verification-everything/tree/master/io/src/main/java/socket/nio file https://github.com/victorsheng/verification-everything/tree/master/io/src/main/java/file/nio
示例代码: socket https://github.com/victorsheng/verification-everything/tree/master/io/src/main/java/socket/aio file https://github.com/victorsheng/verification-everything/tree/master/io/src/main/java/file/aio
作为jdk的基础类库,被很多应用使用了,此处列举了几个常见的
http://tomcat.apache.org/tomcat-9.0-doc/config/http.html#Connector_Comparison
Prior to Jetty 9, the type of the connector reflected both the protocol supported (HTTP, HTTPS, AJP, SPDY), and the nature of the implementation (NIO or BIO). From Jetty 9 onwards there is only one prime Connector type (ServerConnector), which is NIO based and uses Connection Factories to handle one or more protocols.
https://www.eclipse.org/jetty/documentation/9.4.x/quickstart-config-what.html#intro-jetty-configuration-connectors
作为nio最常用的封装类库
NIO并没有完全屏蔽平台差异,它仍然是基于各个操作系统的I/O系统实现的,差异仍然存在。使用NIO做网络编程构建事件驱动模型并不容易,陷阱重重。
推荐大家使用成熟的NIO框架,如Netty,MINA等。解决了很多NIO的陷阱,并屏蔽了操作系统的差异,有较好的性能和编程模型。