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
Using join() on the current thread is a best practice for ensuring proper synchronization.
B
The code will throw a runtime exception unrelated to deadlock because join() is misused here.
C
join() introduces a brief sleep that delays the thread momentarily before resuming execution.
D
Calling join() on the current thread causes it to wait for itself indefinitely, resulting in a deadlock.
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | busemagngr | 2 | 2 | 1m 00s | 140 |
| #2 | michael.2103ll | 1 | 1 | 0m 00s | 100 |
| #3 | parth.taur227 | 1 | 1 | 1m 03s | 37 |
Items per page:
10
1 – 3 of 3
