Custom Configurable Execution Contexts
Inject Custom Execution Context
class MyBlockingClass @Inject()(implicit executionContext: MyCustomExecutionContext)
Define Custom Execution Context
- the base
CustomExecutionContext
allows execution context to be configured viaapplication.conf
- by the name
threadpools.my.blocking.ec
@Singleton
class MyCustomExecutionContext @Inject() (system: ActorSystem)
extends CustomExecutionContext(system, "threadpools.my.blocking.ec")
Configure Execution Context
configure in application.conf
threadpools.my.blocking.ec.executor = "thread-pool-executor"
threadpools.my.blocking.ec.thread-pool-executor.fixed-pool-size = 8
Configure Guice to Inject Custom Execution Context
in module.scala
class Module extends AbstractModule {
override def configure(): Unit = {
bind(classOf[MyCustomExecutionContext]).asEagerSingleton()
}
}