[concurrency-interest] CompletableFuture.get() swallows thread interrupt flag on Java 11

Alex Otenko oleksandr.otenko at gmail.com
Thu Oct 15 02:23:41 EDT 2020


Does it reproduce if you remove the line that completes the future?

On Thu, 15 Oct 2020, 04:36 Jens Wilke via Concurrency-interest, <
concurrency-interest at cs.oswego.edu> 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
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20201015/08d54226/attachment.htm>


More information about the Concurrency-interest mailing list