Atomicity: do not do, do not give up halfway

Origin:

Atomicity is a very common kind of operation in the programming world, such as database operation transaction, is an important means to avoid dirty data

Members of the

  • Synchronized: Synchronized. Synchronized: Synchronized. Synchronized: Synchronized

  • If the value stored at the address is equal to the expected value A, then the value at the address is assigned to the new value B. Otherwise, nothing is done.

So the CAS operation is a circular process

use

-AtomicInteger: indicates the basic data type of atomic operations

  • AtomicIntegerArray: Atomic operation array type
  • AtomicReference: Indicates the type of an atomic operation reference
  • AtomicStampedReference: A version stamp is used to record the version number after each change, so that ABA does not exist

ABA problem: you want to reach the desired value, but there is a change in the middle, to solve this problem, you can add a marker bit or version number when the version is increased by 1, to mark the move a few steps;

Common Interview Questions

Are I ++ and ++ I atomic operations?

In terms of bytecode, it’s multiple steps