Scala多线程闭包例子

来源:互联网 发布:苹果mac自带壁纸高清 编辑:程序博客网 时间:2024/05/17 23:33

 var time = System.currentTimeMillis()
    var count = 0;
    for (i <- (1 to 1000000)) {
      if (i % 2 == 0) count += 1
    }
  

    val c = for {
      i <- (1 to 1000000).par
      if (i % 2 == 0)
    } yield i
   

    val d = Stream.range(1, 1000000).filter(_ % 2 == 0)
  

    val a = new AtomicLong(0)
    for (i <- (1 to 1000000).par)
      if (i % 2 == 0) {
        a.incrementAndGet
      }

 

 

原创粉丝点击