File tree Expand file tree Collapse file tree 7 files changed +38
-0
lines changed Expand file tree Collapse file tree 7 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ ## BIO
2+ Block-IO:InputStream和OutputStream,Reader和Writer
3+
4+ 同步阻塞:
5+
6+ ![ ] ( https://github.com/xbox1994/2018-Java-Interview/raw/master/images/BIO.png )
7+
8+ ## NIO
9+ NonBlock-IO:Channel、Buffer、Selector。IO多路复用、同步非阻塞
10+
11+ 同步非阻塞:
12+
13+ ![ ] ( https://github.com/xbox1994/2018-Java-Interview/raw/master/images/NIO-1.png )
14+
15+ IO多路复用:相当于对同步非阻塞的优化版本,区别在于I/O多路复用阻塞在select,epoll这样的系统调用之上,而没有阻塞在真正的I/O系统调用如recvfrom之上。换句话说,轮询机制被优化成通知机制,多个连接公用一个阻塞对象,进程只需要在一个阻塞对象上等待,无需再轮询所有连接
16+
17+ ![ ] ( https://github.com/xbox1994/2018-Java-Interview/raw/master/images/NIO-3.png )
18+
19+ 在Java的NIO中,是基于Channel和Buffer进行操作,数据总是从通道读取到缓冲区中,或者从缓冲区写入到通道中。Selector用于监听多个通道的事件(比如:连接打开,数据到达)。因此,单个线程可以监听多个数据通道,select方法会一直阻塞,直到channel中有事件就绪:
20+
21+ ![ ] ( https://github.com/xbox1994/2018-Java-Interview/raw/master/images/NIO-2.png )
22+
23+ 与BIO区别如下:
24+
25+ 1 . 通过缓冲区而非流的方式进行数据的交互,流是进行直接的传输的没有对数据操作的余地,缓冲区提供了灵活的数据处理方式
26+ 2 . NIO是非阻塞的,意味着每个socket连接可以让底层操作系统帮我们完成而不需要每次开个线程去保持连接,使用的是selector监听所有channel的状态实现
27+ 3 . NIO提供直接内存复制方式,消除了JVM与操作系统之间读写内存的损耗
28+
29+ ## AIO
30+ Asynchronous IO:基于事件和回调机制、异步非阻塞
31+
32+ ![ ] ( https://github.com/xbox1994/2018-Java-Interview/raw/master/images/AIO.png )
33+
34+ AIO得到结果的方式:
35+
36+ * 基于回调:实现CompletionHandler接口,调用时触发回调函数
37+ * 返回Future:通过isDone()查看是否准备好,通过get()等待返回数据
Original file line number Diff line number Diff line change 1212* [ JVM原理] ( https://github.com/xbox1994/2018-Java-Interview/blob/master/MD/Java基础-JVM原理.md )
1313* [ 集合] ( https://github.com/xbox1994/2018-Java-Interview/blob/master/MD/Java基础-集合.md )
1414* [ 多线程] ( https://github.com/xbox1994/2018-Java-Interview/blob/master/MD/Java基础-多线程.md )
15+ * [ IO] ( https://github.com/xbox1994/2018-Java-Interview/blob/master/MD/Java基础-IO.md )
1516* [ 问题排查] ( http://www.wangtianyi.top/blog/2018/07/20/javasheng-chan-huan-jing-xia-wen-ti-pai-cha/?utm_source=github&utm_medium=github )
1617### Web框架、数据库
1718* [ Spring] ( https://github.com/xbox1994/2018-Java-Interview/blob/master/MD/Web框架-Spring.md )
You can’t perform that action at this time.
0 commit comments