Can a Java 8 `Stream` be parallel without you even asking for it?

前端 未结 5 1053
借酒劲吻你
借酒劲吻你 2021-01-01 15:35

As I see it, the obvious code, when using Java 8 Streams, whether they be \"object\" streams or primitive streams (that is, IntStream and friends)

5条回答
  •  情书的邮戳
    2021-01-01 16:07

    This appart is not specification constrained right now, however the short answer is NO. There exist parallelStream() and stream() functions but that just provides you ways to access to a parallel or sequential implementations of common basic operations to process the stream. Currently runtime can't assume that your operations are thread safe without explicit usage of parallelStream() or parallel() call, then default implementation of stream() is to have a sequential behavior.

提交回复
热议问题