If I have an AtomicInteger
that starts out with 0, and it is incremented N times, is the final value guaranteed to be N? I guess it should be as that is the point of having AtomicInteger
as a thread-safe counter, but I just wanted to make sure.
Asked
Active
Viewed 203 times
1 Answers
1
You should have searched before asking this here. From this question,
There are two main uses of AtomicInteger:
- As an atomic counter (incrementAndGet(), etc) that can be used by many threads concurrently
- As a primitive that supports compare-and-swap instruction (compareAndSet()) to implement non-blocking algorithms.
So the answer to your question is Yes

Community
- 1
- 1

Imesha Sudasingha
- 3,462
- 1
- 23
- 34