diff --git a/core/play/src/main/java/play/libs/concurrent/HttpExecution.java b/core/play/src/main/java/play/libs/concurrent/HttpExecution.java index 13285918ab5..85005a41361 100644 --- a/core/play/src/main/java/play/libs/concurrent/HttpExecution.java +++ b/core/play/src/main/java/play/libs/concurrent/HttpExecution.java @@ -28,6 +28,18 @@ public static ExecutionContextExecutor fromThread(ExecutionContext delegate) { return HttpExecutionContext.fromThread(delegate); } + /** + * An ExecutionContext that executes work on the given ExecutionContext. The current thread's + * context ClassLoader is captured when this method is called and preserved for all executed + * tasks. + * + * @param delegate the delegate execution context. + * @return the execution context wrapped in an {@link play.libs.concurrent.HttpExecutionContext}. + */ + public static ExecutionContextExecutor fromThread(ExecutionContextExecutor delegate) { + return HttpExecutionContext.fromThread(delegate); + } + /** * An ExecutionContext that executes work on the given ExecutionContext. The current thread's * context ClassLoader is captured when this method is called and preserved for all executed diff --git a/documentation/manual/working/javaGuide/main/async/code/javaguide/async/controllers/Application.java b/documentation/manual/working/javaGuide/main/async/code/javaguide/async/controllers/Application.java index 2d1b5852e9e..2af76635c8a 100644 --- a/documentation/manual/working/javaGuide/main/async/code/javaguide/async/controllers/Application.java +++ b/documentation/manual/working/javaGuide/main/async/code/javaguide/async/controllers/Application.java @@ -28,7 +28,7 @@ public Application(MyExecutionContext myExecutionContext) { public CompletionStage index() { // Wrap an existing thread pool, using the context from the current thread - Executor myEc = HttpExecution.fromThread((Executor) myExecutionContext); + Executor myEc = HttpExecution.fromThread(myExecutionContext); return supplyAsync(() -> intensiveComputation(), myEc) .thenApplyAsync(i -> ok("Got result: " + i), myEc); }