QuickDevGuide

Home › Play Framework (Java)

Async Actions & Non-Blocking I/O — Play Framework (Java)

Play is built on Pekko (formerly Akka) and is non-blocking: a small thread pool serves many requests. Actions that wait on I/O should return CompletionStage<Result> instead of blocking. Situation Approach Call another HTTP service WSClient (async) → thenApply Run several calls in parallel start them all, then thenCombine / CompletableFuture.allOf Unavoidable blocking (JDBC, legacy SDK) run on a dedicated execution context, never the default one Timeouts .toCompletableFuture().orTimeout(...) or Futures.timeout Inside futures, need request context use HttpExecutionContext / ClassLoaderExecutionContext Blocking on the default dispatcher (Thread.sleep, JDBC calls) can freeze the entire app under load.

Key Takeaways