top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is atomic operation? What are atomic classes in Java Concurrency API?

0 votes
565 views
What is atomic operation? What are atomic classes in Java Concurrency API?
posted Jan 25, 2018 by Frank Lee

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Atomic operations are performed in a single unit of task without interference from other operations. Atomic operations are necessity in multi-threaded environment to avoid data inconsistency.

int++ is not an atomic operation. So by the time one threads read it’s value and increment it by one, other thread has read the older value leading to wrong result.

To solve this issue, we will have to make sure that increment operation on count is atomic, we can do that using Synchronization but Java 5 java.util.concurrent.atomic provides wrapper classes for int and long that can be used to achieve this atomically without usage of Synchronization.

answer Feb 5, 2018 by Ammy Jack
...