The difference between synchronous and asynchronous requests

First, explain the concepts of synchronization and asynchrony

Synchronization means that the sender sends data and waits for the receiver to send back the response before sending the next data packet. Asynchronous communication means that the sender sends data and then sends the next data packet without waiting for the receiver to send back the response.

The concept of synchronous communication mode and asynchronous communication

Synchronous communication requires the communication parties to carry out at the same clock frequency, and coordinate accurately. By sharing a single clock or timing pulse source, accurate synchronization between sender and receiver is ensured, which is high efficiency. Asynchronous communication does not require synchronization between the two parties, and the transceiver can use their own clock source. The two parties follow the asynchronous communication protocol, and the data transmission unit is character. The time interval for the sender to transmit characters is uncertain, and the transmission efficiency is lower than that of synchronous transmission.

The communication choice the consumer uses to invoke the WEB service: synchronous or asynchronous.

Consumers can implement service invocations synchronously or asynchronously. The difference between the two approaches from the user’s point of view is:

Synchronization — consumers invoke services from a single thread; The thread sends the request, blocks while the service runs, and waits for the response. Asynchronous — the consumer invokes the service through two threads; One thread sends the request, and a separate thread receives the response. The terms synchronous and asynchronous are often confused with sequential and concurrent. The latter two terms have to do with the order in which individual tasks must be performed, while synchronous and asynchronous have to do with the way threads perform individual tasks, such as calling individual services. A good way to understand the difference between synchronous and asynchronous calls is to consider the consequences of crash recovery:

Synchronization – If the consumer crashes while blocking while the service is running, when it restarts, it will not be able to reconnect to the call in progress, so the response is lost. The consumer must invoke the procedure repeatedly and hope that it will not crash this time. Asynchronous – If a consumer crashes while waiting for a response after sending a request, it can continue waiting for the response when it restarts, so the response is not lost. Crash recovery is not the only difference between synchronous and asynchronous calls, but if you’re trying to determine which way a particular call goes, thinking about how each call handles crash recovery can often give you a good answer.

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

When using Ajax in Java Web development, it is important to fully understand the difference between synchronous and asynchronous communication models (see Resources). The lack of support for an asynchronous communication model has an impact on client development, integration with Web frameworks, use of tag libraries, IDE use, and thread behavior.

In the synchronous request/response communication model, it is always the browser (as opposed to the Web server, application server, or Web application) that initiates the request (through the Web user). The Web server, application server, or Web application then responds to incoming requests. The user cannot continue to use the browser while the synchronous request/response pair is being processed.

In the asynchronous request/response communication model, communication from the browser (via the Web user) to the Web server, application server, or Web application (and vice versa) is decoupled. In the processing of asynchronous request/response pairs, the Web user can continue to use the browser while the current asynchronous request is being processed. Once the asynchronous request processing is complete, the asynchronous response is communicated (from the Web server, application server, or Web application) back to the client page. Typically, the call has no effect on the Web user during this process; They don’t have to wait for a response.