4

官方文档只描述了如何在scala中使用。http://www.playframework.com/documentation/2.1.0/ThreadPools

Future {
  // Some blocking or expensive code here
}(Contexts.myExecutionContext)

我可以得到这样的执行上下文:

ExecutionContext myExecutionContext = Akka.system().dispatchers().lookup("my-context");

但是如何在代码中添加它呢?

return async(
    future(new Callable<String>() {
        public String call() {
              return doSth();
        }).map(new F.Function<String,Result>() {
           public Result apply(String i) {
              return ok(i);
           }
        })  
4

1 回答 1

5

我想答案应该是:</p>

    ExecutionContext myExecutionContext = Akka.system().dispatchers().lookup("my-context");
    return async(
            Akka.asPromise(Futures.future(new Callable<String>() {
              public String call() {
                return doSth();
              }   
            }, myExecutionContext)).map(new F.Function<String,Result>() {
              public Result apply(String i) {
                return ok(i);
              }
            })
    );
于 2013-05-06T02:10:39.873 回答