Sync/asynchronous and blocking/non-blocking differences __ Sync

Source: Internet
Author: User

Synchronous, asynchronous: Concept: Notification mechanism of the message to explain: related to the IO notification mechanism; The so-called synchronization, is to initiate the call, the caller processing the message, must wait for processing to directly return the result, not finished before is not returned, the caller actively wait for the result; is returned directly by the caller, but does not return the result, etc. when the message is processed, the caller is notified by state, notification, or callback function, and the caller passively receives the result. blocking, non-blocking: concept: The state of the program when it waits for the call result: It involves CPU thread scheduling; The so-called blocking, is the call result returned before the execution thread will be suspended, do not release the CPU execution power, the thread can not do other things, can only wait, Only wait until the result of the call is returned, can proceed to proceed; the so-called non-blocking, is not to get the call results, not always wait, the thread can be executed, if it is synchronized, through polling to check that there is no call results returned, if it is asynchronous, will notify the callback.
Classic Story case: characters: Old props: ordinary kettle (water boil not sound); the kettle (water burns out) case:               &NBSP ;        1, sync blocking:                       &NBSP ;       Old Zhang in the kitchen to boil water with a common kettle, has been waiting in the kitchen (blocking), staring at the boiling (sync);         &NB           Sp    2, asynchronous blocking:                             &NB An SP; old Zhang in the kitchen with a ring kettle boiling water, has been in the kitchen medium (blocking), until the kettle makes a noise (asynchronous), old Zhang know that the waters boil;

                       3, sync non-blocking:       &NBSP ;                       Old Zhang in the kitchen with a common kettle to boil water, in the boiling water, to the living room to watch TV (non-blocking), And then go to the kitchen and watch the water boil. No                               & nbsp                           (poll check sync results);

4, asynchronous non-blocking: Old Zhang in the kitchen with a ring kettle boiling water, in the process of boiling water, to the living room to watch TV (not blocked), when the kettle makes a noise (asynchronous), Old Zhang will know The water has boiled away.
Note: 1, the usual IO, NIO operations, are synchronized; 2, JDK1.7 provides classes for AIO asynchronous operations, such as Asynchronoussocketchannel, Asynchronousserversocketchannel          Java can also implement asynchronous operation through multiple threads, in the open thread, through callback. ......


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.