Java Concurrency Concept-1

Source: Internet
Author: User

One, synchronous and asynchronous:

Synchronization: The caller needs to wait for the callee to respond before the next action can take place.

Async: The caller does not need to wait for the callee to respond and proceed directly to its own action. There may be a response from the callee at some point in the future.

  

Two, concurrency and parallelism

Parallelism refers to the occurrence of two or more events at the same time, while concurrency refers to two or more events that occur within the same interval .

  

Three, critical section

The code that accesses the critical resource in each process is called a critical section (a Critical section) (A critical resource is a shared resource that only one process is allowed to use at a time). Only one process is allowed to enter the critical section at a time.

The scheduling principle of a process entering a critical section is:

1. If there are several processes that require access to an idle critical section, only one process is allowed to enter at a time. 2. At any time, there must be more than one process in the critical area.  If a process has entered its own critical section, all other processes attempting to enter the critical section must wait.  3, the process of entering the critical area should be exited within a limited time so that other processes can enter their critical areas in time.   4, if the process can not enter their own critical section, you should give up the CPU, to avoid the process of "busy" phenomenon. Four, blocking and non-blocking blocking are not allowed to come back,
Non-blocking is what you do first, I'll see if there's anything else. Blocking and non-blocking are often used to describe the interaction between multiple threads. For example, if a thread occupies a critical section resource, all other threads that need the resource must wait in this critical section, waiting for the thread to hang. This situation is blocking. At this point, if the resource-hogging thread has been reluctant to release resources, all other threads that are blocking the critical section will not work.

Non-blocking allows multiple threads to enter the critical section at the same time

Blockingqueue in Java is the blocked Representative class

Java Concurrency Concept-1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.