我按照以下顺序放了两个promises,并在获得promises后立即将promises映射到字符串结果。第二个承诺结果将无法返回。该错误仅发生在第二个promise映射中。这是在Play 2.1 Java下测试的。有没有更好的方法来解决这个问题?
Promise<String> prom1 = Akka.future(new Callable<String>() {
public String call() {
// intensive computation
return "prom1 ret";
}
});
Promise<String> prom2 = Akka.future(new Callable<String>() {
public String call() {
// intensive computation
return "prom2 ret";
}
});
String ret1 = prom1.map(
new Function<String,String>() {
public String apply(String str) {
return str + " affix";
}
}
).get();
String ret2 = prom2.map(
new Function<String,String>() {
public String apply(String str) {
return str + " affix";
}
}
).get();
我得到了例外:
play.api.Application$$anon$1: Execution exception[[RuntimeException: java.util.concurrent.TimeoutException: Futures timed out after [10000 milliseconds]]]
at play.api.Application$class.handleError(Application.scala:289) ~[play_2.10-2.1.0.jar:2.1.0]
at play.api.DefaultApplication.handleError(Application.scala:383) [play_2.10-2.1.0.jar:2.1.0]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anon$2$$anonfun$handle$1.apply(PlayDefaultUpstreamHandler.scala:132) [play_2.10-2.1.0.jar:2.1.0]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anon$2$$anonfun$handle$1.apply(PlayDefaultUpstreamHandler.scala:128) [play_2.10-2.1.0.jar:2.1.0]
at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play_2.10-2.1.0.jar:2.1.0]
at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play_2.10-2.1.0.jar:2.1.0]
java.lang.RuntimeException: java.util.concurrent.TimeoutException: Futures timed out after [10000 milliseconds]
at play.libs.F$Promise$6.apply(F.java:401) ~[play_2.10-2.1.0.jar:2.1.0]
at scala.concurrent.Future$$anonfun$map$1.liftedTree2$1(Future.scala:253) ~[scala-library.jar:na]
at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:249) ~[scala-library.jar:na]
at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:249) ~[scala-library.jar:na]
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:29) ~[scala-library.jar:na]
at akka.dispatch.BatchingExecutor$Batch$$anonfun$run$1.liftedTree1$1(BatchingExecutor.scala:67) ~[akka-actor_2.10-2.1.0.jar:na]
Caused by: java.util.concurrent.TimeoutException: Futures timed out after [10000 milliseconds]
at scala.concurrent.impl.Promise$DefaultPromise.ready(Promise.scala:96) ~[scala-library.jar:na]
at scala.concurrent.impl.Promise$DefaultPromise.ready(Promise.scala:58) ~[scala-library.jar:na]
at scala.concurrent.Await$$anonfun$ready$1.apply(package.scala:86) ~[scala-library.jar:na]
at scala.concurrent.Await$$anonfun$ready$1.apply(package.scala:86) ~[scala-library.jar:na]
at akka.dispatch.MonitorableThreadFactory$AkkaForkJoinWorkerThread$$anon$3.block(ThreadPoolBuilder.scala:173) ~[akka-actor_2.10-2.1.0.jar:na]
at scala.concurrent.forkjoin.ForkJoinPool.managedBlock(ForkJoinPool.java:2803) ~[scala-library.jar:na]