Where is the streams API using ForkJoinPool?

Brian Goetz brian.goetz at oracle.com
Sat Oct 12 14:40:20 UTC 2019


It’s subtle, but it’s in there.  Here’s where parallel execution of forEach() bottoms out:

@Override
public <S> Void evaluateParallel(PipelineHelper<T> helper,
                                 Spliterator<S> spliterator) {
    if (ordered)
        new ForEachOrderedTask<>(helper, spliterator, this).invoke();
    else
        new ForEachTask<>(helper, spliterator, helper.wrapSink(this)).invoke();
    return null;
}

The tasks that get built in this way are fork join tasks; calling invoke() on them submits them to a fork join pool, and the FJ implementation uses the common pool.  

> I am looking for the place in source code where the *new* Streams API is using the ForkJoinPool for it's parallel execution. Could anyone point me where should I look? It's not in the source of java.util.stream.*




More information about the jdk-dev mailing list