Courseiva
Question 31 of 513
Working with Arrays and CollectionshardMultiple ChoiceObjective-mapped

1Z0-829 Working with Arrays and Collections Practice Question

You are developing a high-frequency trading application that processes a stream of market data ticks. Each tick is an immutable object containing timestamp, price, and volume. The ticks arrive in real time and must be stored in a collection for later analysis. The collection is accessed by multiple threads: one producer thread adds ticks, and multiple consumer threads periodically iterate to compute moving averages. The system must minimize latency for the producer and ensure that consumers see a consistent snapshot of data without interfering with ongoing writes. You initially used a synchronized ArrayList, but profiler results show high contention and poor throughput. You consider the following approaches. Which one best addresses the requirements?

⚠ Common exam trap

A common mix-up: candidates assume CopyOnWriteArrayList is the best choice for concurrent reads and writes, but they overlook its write-cost penalty, which is disastrous for high-frequency producers; the correct solution uses a non-blocking collection with a snapshot mechanism.

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

Use a ConcurrentLinkedDeque for writes and have consumers obtain a consistent snapshot by calling toArray() on the deque. The toArray() operation is O(n) but provides a point-in-time view without blocking the producer.

ConcurrentLinkedDeque allows lock-free, non-blocking writes (ideal for low-latency producers) and calling toArray() provides a consistent, immutable snapshot of the deque at that instant without blocking concurrent modifications. This satisfies the requirement for multiple consumers to see a consistent view while the producer continues writing with minimal latency.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Replace ArrayList with CopyOnWriteArrayList, which provides thread-safety without explicit synchronization and allows concurrent iteration while modifications occur.

    Why it's wrong here

    CopyOnWriteArrayList creates a new copy on every write, causing O(n) cost per insertion. In a high-frequency trading scenario with many writes, this leads to excessive memory allocation and latency, making it unsuitable for the producer.

  • Use a ConcurrentLinkedDeque for writes and have consumers obtain a consistent snapshot by calling toArray() on the deque. The toArray() operation is O(n) but provides a point-in-time view without blocking the producer.

    Why this is correct

    ConcurrentLinkedDeque offers lock-free, low-latency writes for the producer. Calling toArray() creates a snapshot that is consistent as of the moment of the call, allowing consumers to iterate without interference. The O(n) cost of toArray() is acceptable if consumers iterate infrequently relative to the number of writes.

  • Use a ConcurrentLinkedDeque and have consumers acquire a read lock when iterating, while the producer uses a write lock. This provides fine-grained locking and reduces contention.

    Why it's wrong here

    ConcurrentLinkedDeque is non-blocking and does not support explicit locks. Attempting to acquire locks on it would cause compilation errors or misuse. Additionally, it does not provide consistent snapshots because its iterator is weakly consistent.

  • Maintain two synchronized ArrayLists. The producer writes to one list while consumers read from the other. Periodically, swap references using an AtomicReference. This allows lock-free reads after the swap.

    Why it's wrong here

    This double-buffering approach requires careful coordination to ensure that consumers do not read a partially updated list. The swap itself is atomic, but if the producer is writing to the 'active' list while consumers read the 'snapshot' list, the snapshot becomes stale. This design does not provide real-time access to the latest data and may miss ticks.

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 →

How Courseiva writes practice questions · Editorial policy

Last reviewed: Jun 25, 2026

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.

Loading comments…

Sign in to join the discussion.

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.