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) {
3535// test2(persons);
3636// test3(persons);
3737// test4(persons);
38- test5 (persons );
38+ // test5(persons);
39+ test6 (persons );
3940 }
4041
4142 private static void test1 (List <Person > persons ) {
@@ -97,4 +98,22 @@ private static void test5(List<Person> persons) {
9798
9899 System .out .println (ageSum );
99100 }
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+ }
100119}
You can’t perform that action at this time.
0 commit comments