Java Interview Question 5: What is serial, parallel, concurrent, synchronous, and asynchronous?

① Concurrency:

      Concurrent programming is also called multithreaded programming. The essence of concurrency is that a physical CPU is multiplexed between several programs, and limited resources are shared by multiple users to improve efficiency. The number of tasks exceeds the number of cores of the CPU. Through the task scheduling algorithm of the operating system, multiple tasks can be executed together. It is impossible for a CPU to run more than one thread at the same time. It can only divide the CPU time into multiple time periods , and then divide each time period into multiple threads for execution. Other threads are in a suspended state. This method is called Concurrency.

②Parallel:

      Two or more events or activities occur at the same time . In a multi-program environment, the program is allowed to be executed on different CPUs at the same time. When the system has more than one CPU, the operations of the threads may be non-concurrent. The threads are executed on different CPUs, and they can execute simultaneously without preempting CPU resources.

③ Serial and parallel:

      Serial means that when there are multiple tasks, each character is executed in sequence , and the next task can be completed only after completing one task . Parallel is that multiple tasks can be executed at the same time, and asynchronous is a prerequisite for multiple tasks to be parallel, that is, parallel threads must be executed asynchronously)

④Synchronous and asynchronous:

      Synchronous and asynchronous refer to whether new threads can be opened. Synchronization cannot start a new thread, but asynchronous is possible. Asynchrony and synchronization are relative. Synchronization is performed sequentially. If one is executed, then the next one needs to be waited and coordinated. Asynchrony is independent of each other. In the process of waiting for an event, continue to do your own thing, without waiting for the completion of the previous event before continuing to work. Threads are a way to achieve asynchrony. Asynchrony means that the main thread that calls the method does not need to wait for the completion of another thread synchronously, so that the main thread can do other things. Asynchrony means that a call request is sent to the callee, and the callee can do other things without waiting for the return of the result. The realization of asynchrony can adopt multi-thread technology or hand it over to other threads for processing. For example, synchronization: In the case of multitasking, only one task B can be executed after the execution of one task A is completed, and there is only one thread; asynchronous: multiple threads, one task A is executing, and another task B can be executed at the same time, and task B is not used Wait for task A to finish before executing, which promotes the existence of multiple threads.

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/Sunshineoe/article/details/114891882