0Pricing
Java Academy · Lesson

Async Requests

sendAsync and CompletableFuture.

Asynchronous Requests

Blocking on every HTTP call wastes threads. The JDK HTTP client offers sendAsync, which returns a CompletableFuture immediately and performs the work on a background executor.

This lets you fire many requests concurrently and compose their results without manually managing threads.

send vs sendAsync

The signatures differ in what they return:

  • send returns HttpResponse<T> and blocks, declaring IOException and InterruptedException.
  • sendAsync returns CompletableFuture<HttpResponse<T>> and never blocks; errors surface through the future.

All lessons in this course

  1. java.net.http.HttpClient
  2. Async Requests
  3. Request Bodies and Headers
  4. Handling Responses
← Back to Java Academy