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

ThreadPerTaskExecutor of CompletableFuture makes it unreliable

    Details

      Description

      A DESCRIPTION OF THE PROBLEM :
      The documentation of CompletableFuture (https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html) 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)

      This means these methods cannot be used reliably when you don't know for sure that the environment, where your application runs, creates the common pool with a default parallelism of at least two.
      Otherwise execessive use of these methods can cause an `OutOfMemoryError`.

      A good example for this is https://bugs.mojang.com/browse/MC-137353.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Maybe `CompletableFuture` should use a replacement pool with at least two workers, or commonPool() should always have at least two workers (might break existing programs)?

        Attachments

          Activity

            People

            • Assignee:
              dl Doug Lea
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: