Several concepts you need to know about java concurrency (1)

Recently I was reading the book "Java High Concurrency Programming", I learned some concurrency related concepts, and shared my own understanding

. Synchronization : Once a method call starts, the method caller must wait for the result to return before continuing to perform subsequent actions

Example: teacher Ask Xiaoming in class and ask Xiaoming to give an answer immediately. At this time, the teacher is doing a synchronous operation to Xiaoming. The teacher needs to wait for Xiaoming's answer before continuing the follow-up work.

Asynchronous : Once the method call starts, the method call will return immediately, and the caller can continue Follow-up action. The real method execution will start another thread for execution. The whole process will not hinder the work of the method caller.

Example : The teacher assigns the students homework in the evening before class. When the teacher goes to work the next day, he can check the homework of the classmates in the car, instead of waiting for the students to complete the homework. get off work. This is asynchronous


concurrency : multiple tasks are executed "alternately", and the execution of multiple tasks may appear serial.
When the CPU is executing, if there is only one CPU, multiple tasks will be executed alternately. In this case, it is concurrent.

Parallelism : When the CPU is executed in the true sense of "concurrent" execution
, if there are multiple CPUs, multiple tasks will be executed. It will not be executed alternately, but will be executed together. In this case, it is a parallel

critical section: a common resource can be used by multiple threads, but at a time, only one thread can use it. Once occupied, other threads want to use it. Can only wait

Example : There is only one TV at home, my mother wants to watch variety shows, my father wants to watch sports programs, and I want to watch cartoons, but the TV can only play one program, my mother is watching a variety show, and my father and I can only wait for my mother to watch it. After that, you can watch the show you want to watch. TV is a public resource

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326383547&siteId=291194637