Atomiclongfieldupdater atomic class of Java concurrency_ Power node Java college sorting
Atomiclongfieldupdater introduction and function list
Atomiclongfieldupdater can perform atomic updates on members of type 'volatile long' of a specified class. It is based on the reflection principle.
Atomiclongfieldupdater function list
Atomiclongfieldupdater example
Operation results:
id=1000
Source code analysis of atomiclongfieldupdater (based on jdk1.7.0_40)
Atomiclongfieldupdater complete source code
Let's analyze longfieldtest Java process.
1. newUpdater()
The source code of newupdater () is as follows:
Description: newupdater () is used to obtain an object of atomicintegerfieldupdater type.
It actually returns the casupdate object or the lockedupdater object; Which class to return depends on whether the JVM supports CAS functions of long type. Casupdate and lockedupdater are subclasses of atomicintegerfieldupdater, and their implementation is similar. The following will be described with casupdate.
The source code of casupdater class is as follows:
Note: it is actually operated through CAS function. If the value of the long object of the class is expect, set its value to update.