Java nio-Understanding Synchronous, asynchronous, blocking, and non-blocking

Source: Internet
Author: User

Understanding synchronous, asynchronous, blocking, and non-blocking conclusion: Blocking, non-blocking is independent of synchronous asynchrony. Turn to knowing

"Blocking" and "non-blocking" and "synchronous" and "asynchronous" cannot simply be literally understood, providing an answer from a distributed system perspective.
1. Synchronous and asynchronous
Synchronous and asynchronous attention is message communication mechanism(Synchronous communication/asynchronous Communication)
The so-called synchronization is that when a * call is issued, the * call does not return until the result is obtained. But once the call returns, it gets the return value.
In other words, it is the result of the * caller actively waiting for this * call *.

While Async is the opposite, * Call * after the issue , the call returned directly, so no results were returned.。 In other words, when an asynchronous procedure call is made, the caller does not get the result immediately. Instead, the caller is notified by status, notification, or by a callback function to handle the call after the * call * is issued.

Typical asynchronous programming models like node. js

To cite a popular example:
You call the bookstore boss there is no "distributed System" this book, if it is a synchronous communication mechanism, the bookstore owner will say, you wait, "I check", and then start to check Ah, and so check (maybe 5 seconds, may be a day) to tell you the results (return results).
and the asynchronous communication mechanism, the bookstore owner directly told you I check Ah, check the phone to you, and then directly hung up (do not return the results). And then check it out and he'll call you on his own initiative. Here the boss calls back by "callback" this way.

2. Blocking and non-blocking
Blocking and non-blocking concerns are The program waits for the call result ( message that the status of the return value).

A blocking call means that the current thread is suspended until the call results are returned. The calling thread will not return until the result is obtained.
A non-blocking call means that the call does not block the current thread until the result is not immediately available.

Or the above example,
You call to ask the bookstore owner there is a "distributed System" this book, if you are blocking calls, you will always put yourself "hang" until the book has no results, if the non-blocking call, you don't care if the boss has told you, you have to play the first side, Of course, you'll have to check the boss for a few minutes occasionally.
Here the blocking is independent of the non-blocking and whether synchronous asynchronous. It has nothing to do with how the boss responds to your results.

Blocking and non-blocking are independent of synchronous asynchronous

Java nio-Understanding Synchronous, asynchronous, blocking, and non-blocking

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.