Reprinted, please indicate the original source, thank you!
JAVA server or backend requires a lot of high concurrency computing, so high concurrency is particularly important in the JAVA server or back-end programming.
First of all, there are several concepts:
1. synchronous and asynchronous
Synchronous and asynchronous is a call to describe the method, must be synchronized and so on method invocation can continue only after the end of the follow-up operation, and will return to the asynchronous method invocation (the real execution in another thread) can continue to follow-up operation.
2. concurrency and parallelism
These two concepts are said the execution of 2 or more tasks together, and focused on the concurrent multi task executes, is a point in time only one task (time is very small, and the debris) is the true meaning of the parallel execution at the same time (a fragment of time more than 1 tasks in the implementation of).
3. critical region
The concept of critical zone is very important is that multiple threads will operate to, is a public resource or the sharing of data, but each operation can only one thread use once the critical region resource consumed by other threads must wait for the release of resources, and in the travel order, critical resources are subject to the protection, if not there will be a problem, not up to the expected effect.
4. blocking and non blocking
Blocking and non blocking is used to describe the interaction between multiple threads (the premise is not a multiple threads), a thread take up critical resources then the other thread must wait for the critical region, blocking is the operating system level pending, context switching, the performance is not high. Blocking if a thread has been occupied and does not release resources, other resources that need this critical area must always wait. Non blocking is running multiple threads at the same time into the critical area, as long as the data is not bad to modify the line.
Due to the presence of critical regions, multithreaded concurrency must be controlled. According to the concurrency control strategy,
can be divided into several types:
blocking, no starvation, barrier free, no lock, no waiting.
- The blockage has already been explained.
- Because direct thread has a priority, if the thread scheduling priority call high priority, then the low priority may have been unable to perform, will be hungry, if the lock is fair, are in accordance with the new first out there is no hunger is no hunger.
- No obstacle blocking is pessimistic locking is multi-threaded together to modify critical data may be modified or bad, so every time a person can be modified, others need to wait, a non blocking scheduling without obstacle said, he is an optimistic lock, his task of multiple threads together to modify critical data it may not be the critical data to modify the bad, so you can let multiple threads have come a strict exit strategy. If a thread is found to encounter data contention and conflict in the critical area operation, he will rollback the operation and try again. Deadlock may occur. A relies on B B dependency A and tries to retry.
- Without locking, there is a constraint on the premise of the barrier free, that is, to ensure that a thread can win, there may be hunger.
- Without waiting, there is a constraint on the premise of no lock, that is, to ensure that all threads can be completed within a limited step.
JAVA memory model (JMM), because concurrent programs are much more complex than serial programs, how to ensure data access consistency and security in concurrent programs? So you need to define some rules to ensure that multiple threads can work effectively and correctly, and that’s where JMM comes from.
The key technologies of JMM are built around the atomicity, visibility and order of multithreading.
The subsequent concurrency series of JMM will be explained in detail in terms of atomicity, visibility, and order.
Individual public number
ingenuity zero public number.Jpg