Scala 程序暂停

来源:互联网 发布:大数据时代的特点 编辑:程序博客网 时间:2024/05/17 06:31

为了测试部分功能,需要程序暂停一下,于是自作聪明想了一下方法:

import org.joda.time.DateTime

val t1 = new DateTime()
      var temp = true
      while (temp) {
        val t2 = new DateTime()
        if (t2.getMillis() - t1.getMillis() > Random.nextInt(100000)) {
          println(t2.getMillis() - t1.getMillis())
          temp = false
        }
      }

结果运行时发现这段代码被无情的优化掉了,压根就没执行。

所以采用了这种方式: Thread.sleep(500),可是这种方式在普通对象中是起作用的,在actor内部就不起作用了。

0 0
原创粉丝点击