Class CustomExecutionContext

  • All Implemented Interfaces:
    Executor, scala.concurrent.ExecutionContext, scala.concurrent.ExecutionContextExecutor
    Direct Known Subclasses:
    CaffeineExecutionContext

    public abstract class CustomExecutionContext
    extends Object
    implements scala.concurrent.ExecutionContextExecutor
    Provides a custom execution context from an Akka dispatcher.

    Subclass this to create your own custom execution context, using the full path to the Akka dispatcher.

    
     class MyCustomExecutionContext extends CustomExecutionContext {
       // Dependency inject the actorsystem from elsewhere
       public MyCustomExecutionContext(ActorSystem actorSystem) {
         super(actorSystem, "full.path.to.my-custom-executor");
       }
     }
     
    Then use your custom execution context where you have blocking operations that require processing outside of Play's main rendering thread.
    See Also:
    Dispatchers, Thread Pools
    • Constructor Detail

      • CustomExecutionContext

        public CustomExecutionContext​(ActorSystem actorSystem,
                                      String name)
    • Method Detail

      • prepare

        public scala.concurrent.ExecutionContext prepare()
        Specified by:
        prepare in interface scala.concurrent.ExecutionContext
      • execute

        public void execute​(Runnable command)
        Specified by:
        execute in interface scala.concurrent.ExecutionContext
        Specified by:
        execute in interface Executor
      • reportFailure

        public void reportFailure​(Throwable cause)
        Specified by:
        reportFailure in interface scala.concurrent.ExecutionContext
      • current

        public Executor current()
        Get this executor associated with the current ClassLoader.

        Note that the returned executor is only valid for the current ClassLoader. It should be used in a transient fashion, long lived references to it should not be kept.

        Returns:
        This executor that will execute its tasks with the current ClassLoader.