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