Play 2.6 ThreadPools exemple not relevant?

I try to recreate different thread pool executors for my play 2.6 apps.
But with the injector system I don’t understand how to.

The example is here :

object Contexts {
  implicit val simpleDbLookups: ExecutionContext = akkaSystem.dispatchers.lookup("contexts.simple-db-lookups")
  implicit val expensiveDbLookups: ExecutionContext = akkaSystem.dispatchers.lookup("contexts.expensive-db-lookups")
  implicit val dbWriteOperations: ExecutionContext = akkaSystem.dispatchers.lookup("contexts.db-write-operations")
  implicit val expensiveCpuOperations: ExecutionContext = akkaSystem.dispatchers.lookup("contexts.expensive-cpu-operations")

How to have an akkaSystem val ?

In fact, that example looks wrong.

If you want to have multiple ExecutionContexts and wire them via Guice you can do the following:

class ExecutionContextProvider @Inject()(akkaSystem: ActorSystem) extends Provider[ExecutionContext] {
   override lazy val get = akkaSystem.dispatchers.lookup("contexts.simple-db-lookups")

class ExectionContextModule extends Module {
override def bindings(environment: Environment, configuration: Configuration): Seq[Binding[_]] = Seq(

// Usage:
class MyDbClass @Inject()()(implicit @Named("db") executionContext: ExecutionContext) {}

i.e you can add multiple bind[ExecutionContext].qualifiedWith("OTHER_NAME") to your project and access them with @Named("OTHER_NAME").

I created a Issue that the example could be improved:

1 Like

Yes, as @schmitch said, the example is outdated.

I would say the correct way to do it now is to use a CustomExecutionContext (Scala & Java docs).