Blocking, non-blocking; synchronous, asynchronous

Synchronous, asynchronous concepts, blocking, non-blocking and all IO (input and output). The simplest is to read the file IO operations. And in this case children to read the file, you can have a variety of ways.

What is synchronous and asynchronous

Synchronous request , A calls B, B is synchronous processing, processed before that he would not notice A, will be clear only after the completion of the notification process A.

Asynchronous request , A calls B, B is asynchronous processing, A tell B upon request I've received a request, and then go to asynchronous processing, after processing and then notify by A. callback, etc.

So, synchronous and asynchronous biggest difference is the implementation of the caller and the return timing . After synchronization refers to the things being done the caller back, asynchronous refers to the callee to return, and then do things, think about how to inform the caller after the finish.

 

What is blocking and non-blocking

Block the request , A calls B, A B has been waiting for the return of something else to do nothing.

Non-blocking request , A calls B, A not B has been waiting for the return, go to busy with other things.

Therefore, blocking non-blocking biggest difference is that in this period of time before being returned result of the caller, if the caller has been waiting for. Blocking means that the caller has been waiting for something else to do nothing. Non-blocking refers the caller to go to busy with other things.

Difference between blocking and non-blocking synchronous, asynchronous

First, as already mentioned, blocking, non-blocking and synchronous, asynchronous target for the fact that not the same. Blocking, non-blocking talking caller , synchronous, asynchronous said that the callee .

Some people think that is one thing children obstruction and synchronous, asynchronous and non-blocking is one thing. But this is not right.

The three models in Java IO

In the Java language, a total of IO offers three models, namely blocking IO (BIO), non-blocking IO (NIO), asynchronous IO (AIO).

There's BIO and NIO are synchronized IO model, that is, non-blocking synchronous blocking IO and IO synchronous, asynchronous IO refers to the asynchronous non-blocking IO.

BIO (Blocking I / O) : synchronous blocking I / O mode, the read data is written to be blocked waiting for its completion within a thread.

NIO (New the I / O) : supports both blocking and non-blocking mode, but mainly use synchronous non-blocking IO.

The AIO (Asynchronous I / O) : non-blocking asynchronous I / O model.

 

For example:

BIO (Blocking the I / O) : there is a row in the kettle to boil water, BIO's mode of operation is called a thread stuck in a kettle that, until the kettle to boil, before going treatment at a kettle. But in fact thread is waiting for the kettle to boil period of time has done nothing.

NIO (New the I / O) : NIO approach is called a thread continually polls each kettle of state to see if there kettle status has changed, so the next step of the operation.

The AIO (Asynchronous the I / O ): one switch is installed above each bottle, after boiling water, the kettle will automatically notify me boil.

 

The IO in Java operating system or by means of the IO model, but is packaged operating system IO model only.

 

More exciting, sweep the micro-channel:

 

 

 

 

Original: https: //mp.weixin.qq.com/s __biz = MzU4NzkwNTMzMg == & mid = 2247483902 & idx = 2 & sn = 835c5edc9478a2d2e91575fcc302dfba & chksm = fde5a1a5ca9228b3d583d359e3d48e01d7b2296e924d6c10c426b8f01299923522c61bb3c995 & mpshare = 1 & scene = 23 & srcid = & sharer_sharetime = 1569287484750 & sharer_shareid = 570a2ed1c2a256d708a76b434f2d7246 # rd?

 

Guess you like

Origin www.cnblogs.com/mzdljgz/p/11576490.html