Calling CompletableFuture.join() could execute task in common pool

XMLWordPrintable

        ADDITIONAL SYSTEM INFORMATION :
        openjdk 25 2025-09-16 LTS
        OpenJDK Runtime Environment Temurin-25+36 (build 25+36-LTS)
        OpenJDK 64-Bit Server VM Temurin-25+36 (build 25+36-LTS, mixed mode, sharing)

        A DESCRIPTION OF THE PROBLEM :
        Calling CompletableFuture.join() from a ForkJoinWorkerThread which comes from a new ForkJoinPool, could cause to help to execute tasks in common pool.

        REGRESSION : Last worked in version 21.0.8


        ---------- BEGIN SOURCE ----------
        try (ForkJoinPool pool = new ForkJoinPool(2)) { // A new pool
        ForkJoinTask<?> task = ForkJoinTask.adapt(() -> {
        Thread thread = Thread.currentThread();
        assertTrue(thread instanceof ForkJoinWorkerThread);
        // submit to common pool
        List<Thread> workers = range(0, 100).mapToObj(i -> CompletableFuture.supplyAsync(() -> {
        LockSupport.parkNanos(1_000_000L);
        return Thread.currentThread();
        })).toList().stream()
        .map(CompletableFuture::join) // join in current ForkJoinWorkerThread
        .toList();
        if (Runtime.version().feature() < 25) {
        // before 25, ForkJoinWorkerThread won't help for a different ForkJoinPool
        assertThat(workers).doesNotContain(thread);
        } else {
        // after 25, the ForkJoinWorkerThread will help even from a different ForkJoinPool
        assertThat(workers).contains(thread);
        }
        });
        pool.execute(task);
        task.join();
        }
        ---------- END SOURCE ----------

              Assignee:
              Viktor Klang
              Reporter:
              Webbug Group
              Votes:
              1 Vote for this issue
              Watchers:
              9 Start watching this issue

                Created:
                Updated:
                Resolved: