-
Enhancement
-
Resolution: Fixed
-
P4
-
14
-
b22
```
public class PostTerminationInterruptStatus {
static int countInterrupted(Thread[] threads) {
int count = 0;
for (Thread thread : threads)
if (thread.isInterrupted())
count++;
return count;
}
public static void main(String[] args) throws Throwable {
final int n = 3;
final Thread[] threads = new Thread[n];
for (int i = 0; i < n; i++) {
threads[i] = new Thread(() -> Thread.currentThread().interrupt());
threads[i].start();
}
System.out.println("" + countInterrupted(threads));
for (Thread thread : threads) thread.join();
System.out.println("" + countInterrupted(threads));
}
}
```
The spec for Thread.interrupt and Thread.isInterrupted say that Thread.interrupt need not have any effect when the target thread has terminated BUT are silent on the question of what happens when Thread.isInterrupted is called when the target thread has terminated. Which suggests that the interrupt status needs to be preserved.
The behavior of Thread is more understandable if we are aware of the implementation maintaining VM-internal state that contains the interrupt status, and that state is discarded on termination.
Currently there is no non-intrusive way of asking whether a thread terminated with the interrupt status set.
JDK developer lore is that the interrupt status was once a field in the java-level Thread class. I think it should be restored.
- csr for
-
JDK-8232676 Thread.isInterrupted() always returns false after thread termination
-
- Closed
-
- duplicates
-
JDK-6908596 Missing memory barriers in Thread interruption logic
-
- Closed
-
- is blocked by
-
JDK-8230424 Use platform independent code for Thread.interrupt support
-
- Resolved
-
- relates to
-
JDK-8233454 Test fails with assert(!is_init_completed(), "should only happen during init") after JDK-8229516
-
- Resolved
-
-
JDK-8233520 Shenandoah: do not sleep when thread is attaching
-
- Resolved
-
-
JDK-8233549 Thread interrupted state must only be accessed when not in a safepoint-safe state
-
- Resolved
-
-
JDK-6313903 Thread.sleep(3) might wake up immediately on windows
-
- Resolved
-