1Z0-829 Controlling Program Flow Practice Question
You are developing a high-frequency trading application that processes a stream of market data ticks. Each tick is represented by a Tick object with fields: long timestamp, String symbol, double price, int volume. Ticks arrive in real-time and must be processed in order. A bug is reported: the application occasionally processes a tick out of order, causing incorrect trade decisions. The processing logic uses a while loop to read from a blocking queue and process each tick. The code is:
BlockingQueue<Tick> queue = new LinkedBlockingQueue<>();
while (true) {Tick tick = queue.take(); process(tick);
}
After investigation, you find that the queue is fed by multiple producer threads that sometimes reorder ticks due to network delays. Which course of action best ensures ticks are processed in the correct chronological order without sacrificing throughput?
⚠ Common exam trap
A common mix-up: candidates think sorting after retrieval (Option B) is sufficient, but they overlook that PriorityBlockingQueue provides automatic ordering at insertion time, which is more efficient and maintains correctness without batching delays.
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 LinkedBlockingQueue with a PriorityBlockingQueue that orders by timestamp.
PriorityBlockingQueue maintains elements in natural order (or by a provided Comparator), so ticks are automatically ordered by timestamp when inserted. This ensures the consumer always processes the chronologically earliest tick first, even if producers add them out of order, without requiring additional sorting or blocking.
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 a SynchronousQueue and have producers wait for the consumer to acknowledge.
Why it's wrong here
SynchronousQueue does not buffer; it would not help reordering.
- ✗
After taking from the queue, sort a batch of ticks before processing.
Why it's wrong here
Does not prevent reordering and adds complexity.
- ✓
Replace LinkedBlockingQueue with a PriorityBlockingQueue that orders by timestamp.
Why this is correct
PriorityBlockingQueue maintains ordering by timestamp.
- ✗
Add a delay before processing to allow out-of-order ticks to arrive.
Why it's wrong here
Introduces latency and does not guarantee order.
Go deeper
Related to this question
About these practice questions
This 1Z0-829 question is part of Courseiva's 513-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
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.