Article Directory
How many types of IO streams are there in java?
(1) Divided by flow, it can be divided into input flow and output flow;
(2) Divided by unit, it can be divided into byte stream and character stream;
Byte stream: inputStream, outputStream;
Character stream: reader, writer;
What is the difference between BIO, NIO, and AIO?
(1) Synchronous blocking BIO
One connection per thread.
Before JDK1.4, the BIO mode was used when establishing a network connection 先在启动服务端socket,然后启动客户端socket,对服务端通信,客户端发送请求后,先判断服务端是否有线程响应,如果没有则会一直等待或者遭到拒绝请求,如果有的话会等待请求结束后才继续执行
.
(2) Synchronous non-blocking NIO
NIO mainly thinks 解决BIO的大并发问题
that BIO是每一个请求分配一个线程
when there are too many requests, each thread occupies a certain amount of memory space, and the server is paralyzed.
JDK1.4 began to support NIO, 适用于连接数目多且连接比较短的架构
such as a chat server , and concurrency is limited to applications.
One request per thread.
(3) Asynchronous non-blocking AIO
One valid request per thread.
JDK1.7 began to support AIO, 适用于连接数目多且连接比较长的结构
such as the photo album server , which fully calls the OS to participate in concurrent operations.