Java Atomic Datatype: Interview Reference

Anish Antony
Javarevisited
Published in
4 min readMar 20, 2021

--

As part of java concurrency, it is introduced some new datatype for concurrency handling. Those are called atomic datatypes. Here in this article, we are exploring those data types.

Photo by Zoltan Tasi on Unsplash

What are Atomic Datatypes?

In Java under the package java.util.concurrent.atomic Contains the classes such as AtomicBoolean, AtomicInteger, AtomicLong, AtomicReference, AtomicLongArray…etc. these classes are called atomic data types. These classes having the methods such as to get(), set(int value), lazySet(int value), compareAndSet(int expect, int update) Which used to read and write on values on the data types.

The Atomic classes are in effect equivalent to volatile + synchronized even though the implementation is different. Inside if you look at the implementation of atomic classes source you can see it is not initialized any synchronization but those are synchronized that's why atomic variables defined lock-free thread-safe programming on single variables. Inside the atomic classes, the values are stored in a volatile variable.

What are the different Atomic Datatypes?

All of the atomic data types are defined inside the package java.util.concurrent.atomic. Here follows the details of different data types inside the package

--

--

Anish Antony
Javarevisited

Fullstack Developer | Blogger | Experience on Java, Python, React, Angular, Golang | http://www.behindjava.com