其他分享
首页 > 其他分享> > 列表分片及并行执行

列表分片及并行执行

作者:互联网

列表分片,及并行执行样例

Set<String> ips = Stream.of("1","2","3","4","5","6","7","8","9","10")
// 按照2个为一组,进行切片操作
List<List<String>> partition = Lists.partition(Lists.newArrayList(ips), 2);
// 切片后,并行执行
IntStream.range(0, partition.size()).parallel().forEach(index -> {
            List<String> subIps = partition.get(index);
            // 每2个为一组数据,进行计算
           
 });

标签:index,partition,List,Lists,列表,ips,分片,并行执行
来源: https://www.cnblogs.com/PythonOrg/p/14234801.html