[concurrency-interest] CompletableFuture.get() swallows thread interrupt flag on Java 11
Jens Wilke
jw_list at headissue.com
Wed Oct 14 23:33:19 EDT 2020
Hello everyone,
finally I am using more of the Java 8 concurrency code (yay!) and found
something strange.
Here is the test code:
Executor executor = Executors.newCachedThreadPool();
Thread t = new Thread(() -> {
while (!Thread.interrupted()) {
CompletableFuture<Void> future = new CompletableFuture<>();
executor.execute(() -> future.complete(null));
try {
future.get();
} catch (InterruptedException e) {
return;
} catch (ExecutionException e) {
e.printStackTrace();
}
}
});
t.start();
Thread.sleep(1000);
t.interrupt();
t.join();
This is supposed to terminate after 1s.
Java version which does not terminate:
openjdk version "11.0.8" 2020-07-14
OpenJDK Runtime Environment (build 11.0.8+10-post-Ubuntu-0ubuntu120.04)
OpenJDK 64-Bit Server VM (build 11.0.8+10-post-Ubuntu-0ubuntu120.04,
mixed mode, sharing)
Java version which does terminate:
java version "1.8.0_162"
Java(TM) SE Runtime Environment (build 1.8.0_162-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode)
Debugging into the CompletableFuture.get() in Java 11 I can find a code
path that resets the interrupt flag but neither restores it or throws
the InterruptedException.
Can "someone" give that a closer look?
Warm regards,
Jens
More information about the Concurrency-interest
mailing list