2019 Baidu JAVA Interview Questions

1. The difference between
bio and nio 1. Bio synchronously blocks io: In this mode, after the user process initiates an IO operation, it must wait for the completion of the IO operation. Only when the IO operation is actually completed, the user
The process can run. JAVA's traditional IO model belongs to this way!
2. Nio synchronous non-blocking I/O; java NIO uses a two-way channel for data transmission, and on the channel we can register the events we are interested in: connection events, read and write events;
NIO mainly has three core parts: Channel, Buffer, Selector. Traditional IO operates based on byte stream and character stream, while NIO operates based on Channel and
Buffer (buffer). Data is always read from the channel to the buffer, or written from the buffer to the channel. Selector (selection area) is used to monitor events of multiple channels
(such as: connection open, data arrival). Therefore, a single thread can monitor multiple data channels.

  1. BIO (Blocking I/O): Synchronous blocking I/O mode, data reading and writing must be blocked in a thread to wait for it to complete. This uses the classic boiling water example,
    this assumes a water boiling scene, there is a row of water pots boiling the water, BIO's work mode is to ask a thread to stay on a water The pot, until the water pot is boiling, do not go to the
    next water pot. But in fact, the thread did nothing while waiting for the water pot to boil.
  2. NIO (New I/O): Both blocking and non-blocking modes are supported at the same time, but this is explained by its synchronous non-blocking I/O mode, so what is called synchronous non-blocking? If you take
    boiling water as an example, NIO’s approach is to ask a thread to continuously poll the status of each water bottle to see if the status of the water bottle has changed, and then proceed to the next step from the water. .

Guess you like

Origin blog.51cto.com/15144514/2677740