The basic types of atoms are basically used in the same way, so we only use AtomicInteger as an example here:
We found that the running results were correct.
When we didn't use atomic classes before, we had to lock the method to ensure that the thread ran correctly.
Let’s now take a look at the new classes added in jdk1.8:
LongAccumalator, performs custom operations.
Of course, we can change the custom calculation formula in the middle at will:
For example we can do the product of two numbers:
Atomic update array type:
Update properties of atoms:
Atomic update quote: