Exams Knowledge Hub

MCQs for Competitive Exams, School & College Exams

Module: | Arrays, Strings & Exception Handling

Q57: Consider the following statements regarding the Thread join() method:

1. Invoking the join() method on a specific target thread forces the currently executing parent thread to pause its execution and wait until that specific target thread completely terminates.
2. The join() method internally relies on the wait() mechanism, meaning it physically releases the object's monitor lock while the calling thread is paused.
3. If the target thread has already successfully terminated before the join() method is invoked, the calling thread will be permanently deadlocked waiting for a completion signal that will never arrive.

Which of the above statements is/are correct?
A
Only 1 and 2
B
Only 1 and 3
C
Only 2 and 3
D
1, 2, and 3
✅ Correct Answer: A
🎯 Quick Answer:
The correct combination is 1 and 2. Statement 3 is incorrect because the join() method natively contains a safety check (checking isAlive()). If the target thread is already dead, the join() method simply returns instantaneously without blocking, allowing the caller thread to immediately continue execution.
Concept Definition: The join() method is a fundamental synchronization mechanism that enforces a strict execution sequence, ensuring that one thread's entire lifecycle is completely resolved before another dependent thread is permitted to proceed.
Structural Breakdown: If Thread A executes `threadB.join()`, Thread A halts and enters the WAITING state.
The JVM constantly monitors Thread B. The millisecond Thread B enters the TERMINATED state, the JVM automatically awakens Thread A. Historical/Related Context: The join() method is heavily utilized in MapReduce algorithms or multi-threaded data aggregation.
If the main thread spawns four worker threads to calculate quarterly financial reports, the main thread must execute join() on all four workers.
This guarantees the main thread does not prematurely attempt to print the final yearly total before all quarterly calculations are physically finished.
Causal Reasoning: Because join() is fundamentally built upon the Object.wait() architecture (Statement 2), it operates by entering a synchronized loop checking the thread's alive status.
The moment the target thread terminates, the JVM implicitly fires a notifyAll() command, triggering the wait() loop to exit and releasing the suspended parent thread.