Class ClassLoaderExecutionContext

  • @Singleton
    public class ClassLoaderExecutionContext
    extends Object
    Execution context for managing the ClassLoader scope.

    This is essentially a factory for getting an executor for the current ClassLoader. Tasks executed by that executor will have the same ClassLoader in scope.

    For example, it may be used in combination with CompletionStage.thenApplyAsync, to ensure the callbacks executed when the completion stage is redeemed have the correct ClassLoader:

         CompletionStage<WSResponse> response = ws.url(...).get();
         CompletionStage<Result> result = response.thenApplyAsync(response -> {
             return ok("Got response body " + ws.body() + " while executing request " + request().uri());
         }, clExecutionContext.current());
    Note, this is not a Scala execution context, and is not intended to be used where Scala execution contexts are required.
    • Constructor Detail

      • ClassLoaderExecutionContext

        public ClassLoaderExecutionContext​(Executor delegate)
    • Method Detail

      • current

        public Executor current()
        Get the current 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.

        An executor that will execute its tasks with the current ClassLoader.