More on Atomics
Understand the taxonomy of Java atomic classes including scalars and compound variables. Learn how atomic operations differ from locking, manage contention, and improve performance by minimizing shared state among threads in multithreaded applications.
We'll cover the following...
We'll cover the following...
Taxonomy of atomic classes
There are a total of sixteen atomic classes divided into four groups:
- Scalars
- Field updaters
- Arrays
- Compound variables
Most well-known and commonly used are the scalar ones such as AtomicInteger, AtomicLong, AtomicReference, which support the CAS (compare-and-set). Other primitive types such as double and float can be simulated by casting short or byte values to and from int and using methods floatToIntBits() and doubleToLongBits() for floating point numbers. Atomic scalar classes extend from Number and don’t redefine ...