Play framework 2, how to use execution context in Java?
java, playframework, playframework-2.1
Solution
I think the answer should be:
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);
}
})
);
Problem
The official documents only describe how to use it in scala. http://www.playframework.com/documentation/2.1.0/ThreadPools. ``` Future { // Some blocking or expensive code here }(Contexts.myExecutionContext) ``` I can get the excutionContext like: ``` ExecutionContext myExecutionContext = Akka.system().dispatchers().lookup("my-context"); ``` But how to add it in the code blow? ``` 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); } }) ```