Click to enter _ more _java thousand ask
1. What is the difference between synchronous and asynchronous?
In network programming, we often see synchronous, asynchronous, blocking, non-blocking, four calls and their combinations.
Understanding blocking, non-blocking look here: [What is the difference between blocking and non-blocking][2]
[2]:
The synchronous mode, asynchronous mode is mainly controlled by the client, as follows:
Syncing (sync)
The so-called synchronization, that is, when a function call is issued, the call does not return or continue to perform subsequent operations until the result is obtained.
According to this definition, all methods in Java are synchronous calls and should be performed only after the results have been deferred. When we say synchronous, asynchronous, in general, it refers to tasks that require additional collaboration or time to complete.
Simply put, synchronization is one thing you have to do, and you can do the next thing before you finish it.
For example: b/S mode in the form submission, the specific process is: Client submission request, wait for server processing, processing completed return, in this process the client (browser) can not do other things.
Async (Async)
Asynchronous versus synchronous, when an asynchronous procedure call is issued, the caller can proceed with the subsequent operation until the result has been obtained. When this call is complete, the caller is generally notified by state, notification, and callback. For asynchronous calls, the return of the call is not controlled by the caller.
For the three ways to notify callers, the following is the case:
State
That is, listening to the status of the callee (polling), the caller needs to check every time, the efficiency will be very low.
Notice
When the callee executes, a notification informs the caller that there is no need to consume too much performance.
Callback
Similar to notifications, when the callee executes, it invokes the callback function provided by the caller.
For example: The AJAX request in B/S mode, the process is: Client issued AJAX request---server processing, processing completed client callback, after the client (browser) issued a request, still can do other things.
In summary, the difference between synchronous and asynchronous: After a request is issued, you need to wait for the result before you can continue with other operations.
Java FAQ _01 Basic Concepts (014) _ Synchronous, asynchronous what is the difference