中文字幕精品亚洲无线码二区,国产黄a三级三级三级看三级,亚洲七七久久桃花影院,丰满少妇被猛烈进入,国产小视频在线观看网站

java~ForkJoinPool分而致之處理大(da)數據

ForkJoinPool的思想,是將(jiang)大(da)的集合進行拆分,計算處理(li)之后(hou),再把結果合并,這體現了(le)多(duo)核時(shi)代(dai)的并行計算能力。

集合拆分成元素

  List<Integer> maps = Lists.newArrayList();
  int count = 100;
  for (int i = 0; i < count; i++) {
      maps.add(i);
  }
  StopWatch stopWatch = new StopWatch();
  stopWatch.start();
  List<Integer> odds = new ArrayList<>();
  ForkJoinPool forkJoinPool = new ForkJoinPool(10);
  forkJoinPool.submit(() -> {
      maps.parallelStream()
              .forEach(map -> {
                  if (map % 2 == 0) {
                      odds.add(map);
                      try {
                          Thread.sleep(1);
                      } catch (InterruptedException e) {
                          throw new RuntimeException(e);
                      }
                  }
              });

  }).join();
  stopWatch.stop();
  logger.info(stopWatch.prettyPrint());

大集合拆分成集合

ListUtil.split使用了(le)hutool框架,5.4.5版本提供了(le)集(ji)合(he)拆分功能(neng)

//fork集合
List<List<Integer>> jihe = new ArrayList<>();
jihe = ListUtil.split(maps, 9);
List<List<Integer>> finalJihe = jihe;
forkJoinPool.submit(() -> {
    finalJihe.parallelStream()
            .forEach(map -> {
                logger.info("map size:{}", map.size());
            });
}).join();
posted @ 2022-07-29 16:17  張占嶺  閱讀(215)  評論(0)    收藏  舉報