java CAS

Cas optimistic locking does not lock the entire thread each time, and judges before the operation. Pessimistic locks monopolize the entire thread, and do not allow other threads to operate if the operation is not completed.
The mechanism used for optimistic locking is CAS, Compare and Swap.

CAS has 3 operands, the memory value V, the old expected value A, and the new value B to be modified. Modify memory value V to B if and only if expected value A and memory value V are the same, otherwise do nothing.

Lock programming is avoided, and the version number is used to distinguish.

Guess you like

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