According to the documentation, the easier way to use an actor is :
Promise promiseOfInt = Akka.future( new Callable() { public Integer call() { return ... ; } } );
But the doc also says that with the Java API it will always use the same thread pool (play default thread pool).
The documentation says that there is also an Akka pool for actors. How can I send this actor tasks to the Akka thread pool, not to block common user actions? So I would be able to tune the Akka pool and keep the default pool small.
Thanks, Loic
The Java Akka plugin (play.libs.Akka
) forwards to the Scala plugin (play.api.libs.Akka
), which in turn starts a new Actor system based on the app's configuration. (That's all the plugin does.)
So you would configure that ActorSystem and all its dispatchers (a dispatcher is also an ExecutionContext) using your normal application.conf file based on the akka
config key. These dispatchers are the thread pools the documentation is referring to.
The default thread pool is used when you import play.api.libs.concurrent.Execution.default
. This is a Scala-only API. In Java, this ExecutionContext is always used automatically as soon as you touch futures and promises. This thread pool is actually based on Play's internal actor system, configured via the play
config key.
So in summary, all your actors, when created via the Akka plugin's ActorSystem, will automatically use the Akka thread pool (inside an actor you can refer to that using context.dispatcher
).
Outside actors, you will be using Play's default/internal thread pool.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With