Java Fundamentals Hardening Multi-Threading Note 07: Synchronous, asynchronous, blocking, non-blocking connections and differences

Source: Internet
Author: User

1. Sync:

The so-called synchronization is that when a function call is made, the call does not return until the result is obtained. But once the call returns , you must first get the return value .

In other words, the caller actively waits for the result of this "call".

For synchronous calls, many times the current thread is still active , but logically the current function does not return .

2. Async:

The so-called asynchronous, "call" after the issue, the call returned directly , so did not return the result .

In other words, when an asynchronous procedure call is made, the caller does not get the result immediately. Instead, after the call is issued, the callee notifies the caller by status , notification , or through a callback function to handle the call .

Synchronous and asynchronous are concerned with the message communication mechanism (synchronous communication/asynchronous Communication), to cite a popular example:

Did you call the bookstore owner for the book "Java Virtual machine"?Synchronous communication Mechanism, the owner of the bookstore will say, you wait, "I check", and then start to check, and so on (maybe 5 seconds, may be a day) to tell you the results (return results).
andAsynchronous communication mechanism, the bookstore boss told you directly 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.

3. Blocking Type:

A blocking call means that the current thread is suspended ( thread blocking ) before the call results are returned. Functions are returned only after the result is obtained.

Someone might equate blocking calls with synchronous calls, and in fact he is different. for synchronous calls, many times the current thread is still active, but logically the current function does not return .

4. Non-blocking:

A non-blocking call means that the call does not block the current thread until the result is not immediately available.

blocking and non-blocking is concerned with the state of the program (thread) while it waits for the call result ( message, return value)

Did you call the bookstore owner for the book "Java Virtual machine"?Blocking calls, you will always "hang" yourself until you get the result of the book;non-blocking calls, you don't care if the boss tells you, you go to play first, of course, you have to check the boss occasionally for a few minutes to return the results.here the blocking is independent of the non-blocking and synchronous asynchronous。 It has nothing to do with how the boss responds to your results.


Java Fundamentals Hardening Multi-Threading Note 07: Synchronous, asynchronous, blocking, non-blocking connections and differences

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.