In the interface Stream :
The intermediate operations are classifiable in stateful and stateless. They impact the result of a parallel Stream.
Only two terminal operations are nondeterministic methods: findAny() and forEach(Consumer). They impact the result of a parallel Stream.
The intermediate stateless operations could have a side-effect if they execute a lazy operation. This impact the result of a parallel Stream.
The intermediate operations are classifiable in:
Stateful
Stateless
These are my two question:
Stateless intermediate methods
Stateful intermediate methods
Are these rules correct?
Thanks a lot!
A.
I guess both conditions 1 and 2 are true. I want to add some operations.
reduce
also is part of the stateful operation.
forEach
is part of the stateless operations.
Please note that stateless operations can become stateful if they create side effects.
The third statement is not totally correct. If a stream is ordered and we process it in parallel, the stream will remain ordered when used with the stateless operations. That's why we need to call the method unordered()
on the stream to make it unordered and improve the efficiency.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.