Sync Over Async (ARCH4023)
Esta página aún no está disponible en tu idioma.
Key java.async.blocking-future-get · Severity error · Category async
Blocking on an asynchronous operation with get()/join() from a synchronous context risks deadlock and thread-pool starvation, and defeats the purpose of going async in the first place.
Incorrect
Section titled “Incorrect”public Report build() { CompletableFuture<Data> f = fetchAsync(); Data data = f.get(); // synchronous block return render(data);}Correct
Section titled “Correct”public CompletableFuture<Report> build() { return fetchAsync() .thenApply(this::render); // chain, don't block}Replace the blocking get()/join() with thenApply/thenCompose to chain asynchronously and return the future.