Java Thread Self-Join Deadlock
Which of the following best describes the outcome of the Thread.currentThread().join() call in the code segment below?
public class SelfJoin {
public static void main(String[] args) {
try {
// The current thread waits for its own termination
Thread.currentThread().join();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
System.out.println("This line will never be printed.");
}
}
A
The code will throw a runtime exception unrelated to deadlock because join() is misused here.
B
Calling join() on the current thread causes it to wait for itself indefinitely, resulting in a deadlock.
C
join() introduces a brief sleep that delays the thread momentarily before resuming execution.
D
Using join() on the current thread is a best practice for ensuring proper synchronization.
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE