First, Meet Atomicinteger
See this class when looking at the project code, find its function is simple, is an integer variable type, out of curiosity to see its class definition.
This class is located under Java.util.concurrent.atomic, and under concurrent, it is certain that the class is related to concurrency and atomicity.
Second, further understanding
The source code is very simple, combined with other people's blog, it is basic to understand that the Atomicinteger class is an integer class that provides atomic operations.
Ordinary integer classes, such as int and integer, are not thread-safe for operations such as ++i/i++, and are prone to dirty data in concurrent environments.
Atomicinteger uses the volatile keyword to decorate so that the class can meet thread safety.
Private volatile intvalue; /*** Creates a new atomicinteger with the given initial value. * * @paramInitialValue the initial value*/ PublicAtomicinteger (intInitialValue) {Value=InitialValue; } /*** Creates a new Atomicinteger with initial value {@code0}.*/ PublicAtomicinteger () {}
In the source code also has the embodiment.
"Java" Thread-safe integer class Atomicinteger