Overview of Java 8 Parallel Streams (Part 1)

preview_player
Показать описание
This video gives an overview of Java 8 parallel streams, giving an intro on how aggregate operations in a parallel stream work.
Рекомендации по теме
Комментарии
Автор

2:23 result of the (parallel stream) processing can be deterministic
3:37 sequential stream
4:06 parallel stream
6:23 As much as possible we want to make sure that the lambda expression or method reference that are passed in as the behavior for each of the aggregate function (intermediate) are stateless
9:45 How parallel stream works
9:55 basically a parallel stream is a variant of Map-Reduce model
11:54 a better phase is "split-apply-combine"
12:21 "split" phase - recursion
12:43 It uses Spliterator to split
13:00 you can define a custom Spliterator
14:44 a general rule of thumb - parallel computing works fast when you can give the core sth to work on and it can work for a fairly long amount of time
15:27 apply
16:26 programmers have some control of how many threads there are in the pool
16:42 there are some ways to control the pool in some extents
16:53 combine

ruixue
Автор

Respected Prof Doug,
I have been trying to understand where the associative function for reduce() function comes into picture and how does that help?

In a parallel stream, different chunks will be processed in undeterministic order.
Since the merging is always performed by the Parent task and if the stream is Ordered, parent task will always merge left result with right result and this will be performed recursively
If the Stream source is unordered, the parent task can merge the results in any order.
So, where does associativity come into picture if the reduction depends on stream source is ordered/unordered?

It looks like below gives right result in parallel stream though String concatenation is not associative
String s=myStream.reduce(" ", (s1, s2)->s1+s2)
Please let me know if I am missing something
Regards,
Sanjeev

SanjeevKumar-hjfb