Atomic operations in java - AtomicInteger, AtomicLong, AtomicBoolean


In this thread concurrency tutorial we will learn what are Atomic operations in java with program and examples. We will learn how to perform Atomic operations in thread concurrency in java. We will learn about different atomic classes like AtomicInteger, AtomicLong and AtomicBoolean in java.


Contents of page :
  • Are Classes found in java.util.concurrent.atomic are thread safe?
  • Classes found in java.util.concurrent.atomic

Are Classes found in java.util.concurrent.atomic are thread safe in java?
Java provides some classes in java.util.concurrent.atomic which offers an alternative to the other synchronization. We can use these classes without any explicit synchronization in multithreading environment, because any operation done on these classes is thread safe in java.

Must Read : Primitive, Custom/reference Data Types, Integer, Floating-Point, Character in java


Classes found in java.util.concurrent.atomic are >
  • AtomicInteger - AtomicInteger  provides you with int value that is updated atomically,
  • AtomicLong - AtomicInteger  provides you with long value that is updated atomically, and
  • AtomicBoolean - AtomicInteger  provides you with boolean value that is updated atomically.


Why Classes like AtomicByte, AtomicShort, AtomicFloat, AtomicDouble and AtomicCharacter are not found in java (till java 8) >
AtomicByte, AtomicShort, AtomicFloat, AtomicDouble and AtomicCharacter are present in java (till java 8) because these primitive types like byte, short, float, double are not used too much as compared to int and long in java. So, there is no point of making concurrent classes on top of these primitive types. Although this does not conclude to any concrete reason of their absence in java. You never know they might be introduced in later versions of java.


So in this thread concurrency tutorial we learned what are Atomic operations in java with program and examples. We learned how to perform Atomic operations in thread concurrency in java. We learned about different atomic classes like AtomicInteger, AtomicLong and AtomicBoolean in java.



Having any doubt? or you you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.



/** JavaMadeSoEasy.com */

RELATED LINKS>


Atomic operations in thread concurrency in java >

Atomic operations in java


AtomicInteger in java

Implementation of custom/own AtomicInteger in java


AtomicLong in java

Implementation of custom/own AtomicLong in java


AtomicBoolean in java



Thread concurrency Interviews >

No comments:

Post a Comment