package com.shrimpking.t3;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
/**
* Created by IntelliJ IDEA.
*
* @Author : Shrimpking
* @create 2024/9/11 18:46
*/
public class ThreadStream
{
public static void main(String[] args)
{
List<Integer> list = Arrays.asList(1,2,3,4);
Stream<Integer> stream = list.parallelStream();
Integer result = stream.reduce(
2,
(a,b) -> {
int sum = a + b;
System.out.printf("[累加器] %s : %d + %d = %d%n",Thread.currentThread().getName(),a,b,sum);
return sum;
},
(a,b) -> {
int sum = a + b;
System.out.printf("[组合器] %s : %d + %d = %d%n",Thread.currentThread().getName(),a,b,sum);
return sum;
});
}
}
标签:java,stream,int,sum,ThreadStream,util,import
From: https://blog.51cto.com/u_15356972/12016824