Play Framework 2, how to use runtime context in Java?

Official docs 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 excuctContext like:

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

But how to add it to 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); } }) 
+4
source share
1 answer

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); } }) ); 
+5
source

Source: https://habr.com/ru/post/1479109/


All Articles