Java Thread Interruption Behavior
Consider the InterruptExample class provided below. What is the outcome if a thread executing the run method is interrupted during the call to wait()?
public class InterruptExample implements Runnable {
public void run() {
synchronized(this) {
try {
wait();
} catch (InterruptedException e) {
System.out.println("Interrupted!");
}
}
}
}
A
It will silently resume execution without any notification.
B
It will cause the program to terminate immediately.
C
It will enter a deadlock state and never resume.
D
It will throw an InterruptedException, catch it, and print “Interrupted!”.
Question Leaderboard
Not enough data yet to show leaderboard.
