Re: CompletableFuture.get() swallows thread interrupt flag on Java 11
Alex Otenko via Concurrency-interest <[email protected]> Thu, 15 Oct 2020 07:23:41 +0100
| Newsgroups | gmane.comp.java.jsr.166-concurrency |
|---|---|
| Message-ID | <CANkgWKi+_JSP-pfakhFAOHweHgSGhBZL_2PTWMk=8D+RBi+HNw@mail.gmail.com> |
Does it reproduce if you remove the line that completes the future? On Thu, 15 Oct 2020, 04:36 Jens Wilke via Concurrency-interest, < [email protected]> wrote: > 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 > _______________________________________________ > Concurrency-interest mailing list > [email protected] > http://cs.oswego.edu/mailman/listinfo/concurrency-interest > _______________________________________________ Concurrency-interest mailing list [email protected] http://cs.oswego.edu/mailman/listinfo/concurrency-interest