首页 > 解决方案 > reportFailure 方法在自定义 ExecutionContext 中实际做了什么

问题描述

我写了这段代码

val myEc = new ExecutionContext {
    val tp = Executors.newFixedThreadPool(2)
    def execute(r: Runnable) { tp.submit(r) }
    def reportFailure(t: Throwable) { println("ho ha ha ... something broke!") }
}

val f : Future[Int] = Future(throw new Exception("123"))(myEc)
Await.result(f, Duration.Inf)

程序不打印“ho ha ha”......那么reportFailure的目的是什么?当未来失败时,它不应该被调用吗?

标签: scala

解决方案


推荐阅读