Interview written test materials--Java

1. What are the similarities and differences between synchronous and asynchronous? Under what circumstances are they used respectively? for example

1.1 The concept of
interaction in Java is divided into two types: synchronous and asynchronous:
  synchronous interaction: refers to sending a request, needs to wait for the return, and then can send the next request, there is a waiting process; asynchronous interaction:
  refers to sending a request without waiting Return, you can send the next request at any time, that is, you don't need to wait.

1.2 The difference between the two
is the same: both belong to the interactive mode, and both send requests.
Different places: one needs to wait, one does not need to wait.
To put it simply, synchronization means that one thing must be done one by one, and the next thing can only be done after the previous one is finished. And asynchronous is the result of assigning things to others, and then continuing to do the next thing without waiting for others to return.

1.3 Function
  Synchronization can avoid reading dirty data. It is generally used when sharing a certain resource. If everyone has modification permissions and modifies a file at the same time, it is possible for one person to read the content that another person has deleted. Errors, synchronization will be modified in order. But synchronization can cause deadlock.
  Deadlock refers to a phenomenon in which two or more processes are blocked due to competition for resources or communication with each other during execution. If there is no external force, they will not be able to advance. At this time, the system is said to be in a deadlock state or a deadlock has occurred in the system, and these processes that are always waiting for each other are called deadlock processes.
  Asynchrony can improve efficiency. Now CPUs are all dual-core and quad-core. With asynchronous processing, multiple tasks can be done at the same time. Of course, it must be guaranteed that they can be processed concurrently.

1.4 Example
  Broadcasting is an asynchronous example. The initiator does not care about the state of the receiver. There is no need to wait for the receiver's return information;
  in some cases, our project development will give priority to the asynchronous interaction method that does not need to wait.
  A phone call is an example of synchronization. The originator needs to wait for the receiver to connect the phone before the communication starts. Need to wait for the receiver's return information.
  For example, the bank's transfer system, the save operation of the database, etc., will use synchronous interactive operations.

Guess you like

Origin blog.csdn.net/Daisy74RJ/article/details/129062748