Since we're talking about concurrency, let's start with some related concepts.
Synchronous vs. asynchronous
Synchronous and asynchronous are generally used to describe the invocation of a method at the beginning of a synchronous invocation , and the caller must wait until the method call returns before the subsequent operation can proceed. An asynchronous call is more like a message passing, and once the method call returns, the caller can continue with the next operation
Concurrency and parallelism
Concurrency and parallelism are 2 easy to confuse concepts, they can represent 2 or more than 2 tasks at the same time, but the partial focus is not the same, concurrency is biased to multiple tasks to replace execution, while parallelism is the true meaning of "simultaneous execution", strictly speaking, parallel multiple tasks are real simultaneous execution, and concurrency, This process is only alternating execution, one will run a task, one will run a B task, the CPU between the two fast switching, even if multiple tasks are serial concurrency, due to fast switching, resulting in multi-tasking is the illusion of parallel operation
In fact, if there is only one CPU in the system, and the use of multi-threaded tasks, then these tasks in the real environment can not be real parallel. After all, a CPU can only run one instruction at a time, in which case multithreading is concurrent, not parallel; Real parallelism can only occur in multi-CPU systems
Critical section
A critical section is used to represent public resources, or shared data, that can be used by multiple threads, but only one thread is used each time, and once the critical section resource is used, other threads have to wait, in parallel programs, the critical section is the protected object. If more than one thread is accidentally making changes to the critical section, it can cause data errors
Blocking and non-blocking
Blocking and non-blocking are often used to describe the interplay of multithreading. For example, if a thread occupies a critical section resource, then all other threads that need this resource must wait in this critical section, waiting for it to block, and at this point, if the resource-hogging thread has been reluctant to release the resource, Then other threads that are blocked in this critical section do not work, and the non-blocking meaning is the opposite, and it emphasizes that no one thread can interfere with the execution of other threads, and all threads will try to keep moving forward;
JAVA----Concurrency Learning