File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,8 @@ public static void main(String[] args) {
35
35
// test2(persons);
36
36
// test3(persons);
37
37
// test4(persons);
38
- test5 (persons );
38
+ // test5(persons);
39
+ test6 (persons );
39
40
}
40
41
41
42
private static void test1 (List <Person > persons ) {
@@ -97,4 +98,22 @@ private static void test5(List<Person> persons) {
97
98
98
99
System .out .println (ageSum );
99
100
}
101
+
102
+ private static void test6 (List <Person > persons ) {
103
+ Integer ageSum = persons
104
+ .parallelStream ()
105
+ .reduce (0 ,
106
+ (sum , p ) -> {
107
+ System .out .format ("accumulator: sum=%s; person=%s; thread=%s\n " ,
108
+ sum , p , Thread .currentThread ().getName ());
109
+ return sum += p .age ;
110
+ },
111
+ (sum1 , sum2 ) -> {
112
+ System .out .format ("combiner: sum1=%s; sum2=%s; thread=%s\n " ,
113
+ sum1 , sum2 , Thread .currentThread ().getName ());
114
+ return sum1 + sum2 ;
115
+ });
116
+
117
+ System .out .println (ageSum );
118
+ }
100
119
}
You can’t perform that action at this time.
0 commit comments