[2.1.0-java] ExecutionContext with a future example

401 views
Skip to first unread message

Ryan Means

unread,
Mar 19, 2013, 9:03:29 PM3/19/13
to play-fr...@googlegroups.com
How do you use the ExecutionContext with a future in Play 2.1 for Java? The examples in the doc here: http://www.playframework.com/documentation/2.1.0/ThreadPools are only for Scala. Looks pretty easy to pick which context to use in Scala, but how do you pick which context to use in Java?

I'm looking at this part of the document specifically:

To use this excecution context in Scala, you would simply use the scala Future companion object function:

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

or you could just use it implicitly:

import Contexts.myExecutionContext

Future {
  // Some blocking or expensive code here
}

Mark HUANG

unread,
May 4, 2013, 3:39:52 AM5/4/13
to play-fr...@googlegroups.com
Hi, have u gotten the answer?
 I am also confused of it, cant find any answer.

在 2013年3月20日星期三UTC+8上午9时03分29秒,Ryan Means写道:

Skamander

unread,
May 4, 2013, 4:24:41 AM5/4/13
to play-fr...@googlegroups.com

Rich Dougherty

unread,
May 7, 2013, 11:16:44 PM5/7/13
to play-fr...@googlegroups.com
At the moment you need to use Akka's Futures.future() method to create a scala.concurrent.Future that runs in a particular ExecutionContext. You can then put the Future inside one of Play's F.Promise objects if you like, just wrap the Future using F.Promise's constructor.

Being able to fully control ExecutionContexts is a current weakness of the Java API. We're working to address the problem though. Here's a branch where I'm doing some work at the moment: https://github.com/richdougherty/Play20/tree/java-future (still a work in progress!)

Cheers
Rich


--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages