Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8213114

Java API doc needs update to specify that explicit usage of commonPool() for CompletableFuture may replace it

XMLWordPrintable

      A DESCRIPTION OF THE PROBLEM :
      The documentation for `CompletableFuture` (https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html) only states:
      > All async methods without an explicit Executor argument are performed using the ForkJoinPool.commonPool() (unless it does not support a parallelism level of at least two, in which case, a new Thread is created to run each task).

      However what it does not mention is that when using the commonPool() as explicit executor, it may be replaced as well, see http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/b5c6ff776bee/src/share/classes/java/util/concurrent/CompletableFuture.java#l412

      Example:
      CompletableFuture.runAsync(
            () -> System.out.println(Thread.currentThread().getName()),
            ForkJoinPool.commonPool()
      );


            dl Doug Lea
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: