IO questions have always been one of the hardest hit areas for interviews
But it is very important and must be asked in the interview
A fan who has worked for 7 years sent me a private message, he went to interview 4 Internet companies,
Three companies asked him about network IO, another company asked Netty, and he didn't answer.
Well, for "the difference between IO and NIO", look at the answers of ordinary people and experts.
Ordinary people:
Um. . . . . . . . . .
Expert:
OK, I will answer this question from the following aspects.
First of all, I/O refers to the IO stream, which can realize the reading and writing of data from the disk.
In fact, in addition to disk, memory and network can be used as data sources and destinations for I/O streams.
In Java, there are two ways of character stream and byte stream to realize the operation of data stream.
Secondly, when the program is network-oriented for data IO operations, Java provides a Socket method to achieve it.
In this way, the network transmission of data can be realized.
Socket-based IO communication belongs to blocking IO, that is, when the connection and IO events are not ready, the current connection will be in a blocking waiting state.
If a connection is blocked once, subsequent connections have to wait. So the number of connections the server can handle is very limited.
NIO is a new IO mechanism added in JDK1.4. Compared with traditional IO, NIO has been greatly optimized in efficiency, and several new core components have been added.
Channel, Buffer, Selectors.
In addition, it also provides non-blocking features, so for network IO, NIO is usually also called No-Block IO, non-blocking IO.
That is to say, when network data transmission is performed through NIO, if the connection is not ready or the IO event is not ready, the server will not block the current connection, but will continue to poll subsequent connections for processing.
Therefore, in NIO, the number of connections that the server can process in parallel is greater.
Therefore, in general, the difference between IO and NIO, from the perspective of network IO, the former is blocking IO, and the latter is non-blocking IO.
The above is my understanding of the problem.
Summarize
In the Internet age, network IO is the most basic technology.
Whether it is the service communication in the microservice architecture or the network communication between the application system and the middleware, the importance of network IO is reflected.
If you want to get one-on-one interview guidance and interview materials, you can private message me.
Copyright notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless otherwise stated. Please indicate the source forMic带你学架构
!
If this article is helpful to you, please help to follow and like, your persistence is the driving force for my continuous creation. Welcome to follow the WeChat public account of the same name to get more technical dry goods!
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。