官方文档在哪里说Java的并行流操作使用fork / join? [英] Where does official documentation say that Java's parallel stream operations use fork/join?

查看:130
本文介绍了官方文档在哪里说Java的并行流操作使用fork / join?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我对流框架


  1. 有些东西会创建一个来源 Stream

  2. 实施负责提供 BaseStream#parallel() 方法,它反过来返回一个可以并行运行它的Stream。



< hr>

虽然有人已经找到了一种方法使用自定义线程池和Stream框架的并行执行,我不能在我的生活中找到任何在Java中提到的8默认Java 8并行Stream实现将使用的API ForkJoinPool#commonPool()。 ( Collection#parallelStream() StreamSupport 类,以及API中我不知道的其他可能的并行启用流源。)


While someone has already found a way to use a custom thread pool with Stream framework's parallel executions, I cannot for the life of me find any mention in the Java 8 API that the default Java 8 parallel Stream implementations would use ForkJoinPool#commonPool(). (Collection#parallelStream(), the methods in StreamSupport class, and others possible sources of parallel-enabled streams in the API that I don't know about).

只有我可以从搜索结果中搜索出来的花絮是这些:

Only tidbits that I could gleam off search results were these:

  • State of the Lambda: Libraries Edition ("Parallelism under the hood")
    Vaguely mentions the Stream framework and the Fork/Join machinery.


Fork / Join机器旨在自动执行此过程。


  • JEP 10 7:集合的批量数据操作

    几乎直接表明Collection接口的默认方法#parallelStream()使用Fork / Join实现自身。但是仍然没有关于公共池的信息。

  • JEP 107: Bulk Data Operations for Collections
    Almost directly states that the the Collection interface's default method #parallelStream() implements itself using Fork/Join. But still nothing about common pool.


    并行实现建立在Java引入的java.util.concurrency Fork / Join实现之上7。

    因此: Collection#parallelStream()

    Class Arrays(Javadoc) < br>
    直接表示使用公共池的次数。

    Class Arrays (Javadoc)
    Directly states multiple times that the common pool is used.


    ForkJoin公共池用于执行任何并行任务。


  • 所以我的问题是:

    它在哪里说 ForkJoinPool#commonPool()用于从Java 8 API获取的流上的并行操作?

    Where is it said that the ForkJoinPool#commonPool() is used for parallel operations on streams that are obtained from the Java 8 API?

    推荐答案

    <强> WRT哪里记录了Java 8并行流使用FJ框架?

    Afaik(Java 1.8u5)在并行流的JavaDoc中没有提到它使用了常见的ForkJoinPool。

    Afaik (Java 1.8u5) it is not mentioned in the JavaDoc of parallel streams that a common ForkJoinPool is used.

    但是在
    底部的ForkJoin文档中提到它 http://docs.oracle.com/javase/tutorial/essential/concurrency/forkjoin.html

    Wrt替换线程池

    我的理解是你可以使用自定义的ForkJoinPool(而不是常用的)
    - 参见 Java 8并行流中的自定义线程池 - ,但不是自定义ThreadPool与ForkJoin实现不同(我在这里有一个未解决的问题:如何(全局)替换Java并行流的公共线程池后端?

    My understanding is that you can use a custom ForkJoinPool (instead of the common one) - see Custom thread pool in Java 8 parallel stream -, but not a custom ThreadPool which is different from the ForkJoin implementation (I have an open question here: How to (globally) replace the common thread pool backend of Java parallel streams? )

    Wrt替换Streams api

    您可以结帐 https://github.com/nurkiewicz/LazySeq 这是一个更像Scala的流实现 - 非常好,非常有趣

    You may checkout https://github.com/nurkiewicz/LazySeq which is a more Scala like streams implementation - very nice, very interesting

    PS(wrt ForkJoin和Streams)

    如果您有兴趣,我想说明我偶然发现了使用FJ池的一些问题,请参阅,例如

    If you are interested, I would like to note that I stumbled across some issues with the use of the FJ pool, see, e.g.

    • Nested Java 8 parallel forEach loop perform poor. Is this behavior expected?
    • Using a semaphore inside a nested Java 8 parallel stream action may DEADLOCK. Is this a bug?

    这篇关于官方文档在哪里说Java的并行流操作使用fork / join?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆