java8新特性:并行流与顺序流

 时间:2026-02-14 21:17:19

1、使用顺序流计算0到1亿之和:

@Test

public void test10() {

        Instant start = Instant.now();

        

        LongStream.rangeClosed(1,10000000000000L).reduce(0,Long::sum);

        

        System.out.println("系统执行时间:"+Duration.between(start,Instant.now()).toMillis());

    }

java8新特性:并行流与顺序流

2、执行程序,查看运行时间:

java8新特性:并行流与顺序流

3、使用并行流计算0到1亿之和:

@Test

    public void test11() {

        Instant start = Instant.now();

        LongStream.rangeClosed(1,10000000000000L).parallel().reduce(0,Long::sum);

        System.out.println("系统执行时间:"+Duration.between(start,Instant.now()).toMillis());

    }

java8新特性:并行流与顺序流

4、执行程序,查看并行流运行时间:

java8新特性:并行流与顺序流

5、并行流计算集合数量

public void test12() {

        System.out.println(deptList.stream().parallel().count());

    }

java8新特性:并行流与顺序流

6、执行程序,查看程序运行时间:

java8新特性:并行流与顺序流

  • 如何关闭Windows 8.1 操作系统的快速启动
  • 如何查看电脑最大支持多少内存?
  • 常用的显示器接口有哪几种?
  • apex英雄的最高点在哪,如何上去
  • 液晶电视如何全屏点对点
  • 热门搜索
    小学保护环境手抄报 我的寒假我做主手抄报 我是文明小学生手抄报 清明节祭奠英烈手抄报 幸福班级手抄报 我们的节日中秋节手抄报 中国梦手抄报设计图 童话手抄报图片大全 感恩父母手抄报简单 书香校园手抄报资料