Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.concurrent.Executors
- import javax.inject.Inject
- import scala.concurrent.ExecutionContext
- import akka.actor.ActorSystem
- import play.api.libs.concurrent.CustomExecutionContext
- // way1: extend CustomExecutionContext and pass the name of your Akka dispatcher
- class MyExecutionContext @Inject()(as: ActorSystem) extends CustomExecutionContext(as, "my-context")
- // way2: use Akka lookup method (in fact 100% the same as way1)
- class Aaa @Inject()(as: ActorSystem) {
- implicit val ec: ExecutionContext = as.dispatchers.lookup("my-context")
- }
- // way3: use standard Java Library: call "fromExecutor" or "fromExecutorService" methods of ExecutionContext
- class Bbb {
- implicit val ec: ExecutionContext = ExecutionContext.fromExecutor(Executors.newFixedThreadPool(10))
- }
- // application.conf:
- my-context {
- for-join-executor {
- # The parallelism factor is used to determine thread pool size using the
- # following formula: ceil(available processors * factor). Resulting size
- # is then bounded by the parallelism-min and parallelism-max values.
- parallelism-min = 8
- parallelism-max = 16
- parallelism-factor = 2.0
- task-peeking-mode = "FIFO"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement