Question 333 of 513
1Z0-829 Utilizing Java Object-Oriented Approach Practice Question
A financial services company runs a Java 17 Spring Boot application that processes real-time stock trades. The application uses a class `TradeProcessor` containing a method `void process(Trade trade)`. This method is invoked by multiple threads concurrently. The `Trade` class is immutable and has fields like `String symbol`, `int quantity`, `double price`. The `TradeProcessor` method updates a shared `HashMap<String, Double>` that tracks the average price per symbol. The update logic is: retrieve the current average for the symbol, compute a new average, and put it back. During high-load testing, the average prices are occasionally incorrect. The development team suspects a race condition. Which course of action should be taken to fix the issue with minimal performance impact?
⚠ Common exam trap
Candidates often think `ConcurrentHashMap` alone solves all concurrency issues, but without using atomic methods like `compute`, `merge`, or `replace`, the read-modify-write race condition persists; the exam tests whether you know that `ConcurrentHashMap`'s per-operation thread safety does not automatically compose into atomic compound actions.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Replace `HashMap` with `ConcurrentHashMap` and use the `compute` method to atomically update the average.
`ConcurrentHashMap` provides thread-safe atomic operations like `compute`, which allows you to atomically update the average price per symbol without external synchronization. This avoids the race condition where two threads read the same old average, compute a new one, and overwrite each other's result. Using `compute` ensures the read-modify-write sequence is performed atomically, with minimal performance overhead compared to synchronizing the entire method.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Use an `AtomicReference` to wrap the `HashMap`.
Why it's wrong here
AtomicReference provides atomic reference updates but not atomic updates to the map's entries.
- ✓
Replace `HashMap` with `ConcurrentHashMap` and use the `compute` method to atomically update the average.
Why this is correct
ConcurrentHashMap provides atomic compute methods suitable for this scenario without explicit locking.
- ✗
Synchronize the entire `process` method.
Why it's wrong here
Method-level synchronization would cause high contention and reduce throughput.
- ✗
Change the `HashMap` to `Hashtable`.
Why it's wrong here
Hashtable synchronizes individual operations but not compound actions, so race condition remains.
About these practice questions
Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →
Last reviewed: Jun 25, 2026
This 1Z0-829 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-829 exam.
Question Discussion
Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.
Sign in to join the discussion.