Skip to content
Sharp

Java Threading · interview question

In a high-concurrency e-commerce flash sale, which construct best avoids a race condition when updating inventory levels?

Multiple choiceMediumchapter-15-curatedpremiumjava-threadingvirtual-threads
Choose one answer
Answer and explanation

Correct answer

C. Using AtomicInteger

Why

AtomicInteger provides a non-blocking, thread-safe way to update values, making it ideal for scenarios where updates to shared data must be thread-safe without incurring the overhead of synchronized blocks.

Test yourself on Java Threading

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

Start free test
All Java Threading questions →