Why does Java have no async/await?

The short answer is that the designers of Java try to eliminate the need for asynchronous methods instead of facilitating their use.

According to Ron Pressler’s talk asynchronous programming using CompletableFuture causes three main problems.

  1. branching or looping over the results of asynchronous method calls is not possible
  2. stacktraces cannot be used to identify the source of errors, profiling becomes impossible
  3. it is viral: all methods that do asynchronous calls have to be asynchronous as well, i.e. synchronous and asynchronous worlds don’t mix

While async/await solves the first problem it can only partially solve the second problem and does not solve the third problem at all (e.g. all methods in C# doing an await have to be marked as async).

But why is asynchronous programming needed at all? Only to prevent the blocking of threads, because threads are expensive. Thus instead of introducing async/await in Java, in project Loom Java designers are working on virtual threads (aka fibers/lightweight threads) which will aim to significantly reduce the cost of threads and thus eliminate the need of asynchronous programming. This would make all three problems above also obsolete.

Leave a Comment

tech