Where does official documentation say that Java's parallel stream operations use fork/join?

后端 未结 3 617
陌清茗
陌清茗 2020-12-14 17:16

Here\'s my understanding of the Stream framework of Java 8:

  1. Something creates a source Stream
  2. The implementation is responsible for providing a Ba
3条回答
  •  悲哀的现实
    2020-12-14 17:28

    W.r.t. where is it documented that Java 8 parallel streams use FJ Framework?

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

    But it is mentioned in the ForkJoin documentation at the bottom of http://docs.oracle.com/javase/tutorial/essential/concurrency/forkjoin.html

    W.r.t. replacing the Thread pool

    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? )

    W.r.t. replacing the Streams api

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

    PS (w.r.t. ForkJoin and Streams)

    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?

提交回复
热议问题