Skip to content
Sharp

Concurrency basics · interview question

Which method would you use to update an AtomicInteger only if it currently holds a specific value?

Multiple choiceMediumchapter-15-curatedpremiumconcurrencyatomic-variables
Choose one answer
Answer and explanation

Correct answer

B. CompareAndSet(int expect, int update)

Why

The compareAndSet(int expect, int update) method updates the value of an AtomicInteger only if it currently equals the expected value, providing a way to perform conditional updates atomically.

Test yourself on Concurrency basics

A free test with instant, explained results. No account needed.

Start free test
All Concurrency basics questions →