LearnFrenzy
Sign in Take a free test

Concurrency and Executors · Concurrency and Executors MCQ · Question 13

How atomic classes work Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links