列表分片及并行执行

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

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个为一组数据,进行计算
           
 });

获取差异数据

Sets.SetView<String> needRemoveIps = Sets.difference(ips, existIps);
posted @ 2021-01-05 11:30  SpecialSpeculator  阅读(161)  评论(0编辑  收藏  举报