Question 13
Back to Exercise
How does AtomicInteger.incrementAndGet() stay thread-safe without a lock?
- A It uses synchronized internally
- B It uses a hardware compare-and-set (CAS) instruction, retrying if another thread changed the value Correct
- C It runs on one thread
- D It is not thread-safe
Correct Answer: Option B
LongAdder spreads updates over cells for even less contention.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!