Eight Asynchronous Programming Techniques in Java

This article introduces eight common methods for achieving asynchronous execution in Java, including raw threads, Future, CompletableFuture, Spring @Async, ApplicationEvent, message queues, ThreadUtil, and Guava ListenableFuture, explaining their usage, advantages, and limitations.

Architect
Architect
Architect
Eight Asynchronous Programming Techniques in Java

Asynchronous execution is familiar to developers and can significantly reduce request latency in scenarios such as sending SMS, emails, or updating data.

The article presents eight ways to implement asynchronous programming in Java:

Thread (raw public class AsyncThread extends Thread { ... })

Future (

Future<String> future = executor.submit(new Callable<String>() { ... });

)

CompletableFuture (

CompletableFuture<Integer> cf1 = CompletableFuture.supplyAsync(() -> { ... });

)

Spring @Async (custom thread‑pool configuration and annotated service methods)

Spring ApplicationEvent (event class and listener with @Async handling)

Message Queue (RabbitMQ producer and consumer examples)

ThreadUtil utility (Hutool's ThreadUtil.execAsync(() -> { ... }))

Guava ListenableFuture (using MoreExecutors.listeningDecorator(...) and Futures.addCallback(...))

Each method is described with its core concept, sample code, and typical use‑cases. The article also discusses the shortcomings of Future (no passive result notification, isolation of tasks, limited error handling) and shows how CompletableFuture and Guava’s ListenableFuture address these issues.

Finally, the article concludes that developers can choose the most suitable asynchronous approach based on project requirements, performance considerations, and ecosystem compatibility.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

javaAsynchronousCompletableFutureThreadGuavaFuture
Architect
Written by

Architect

Professional architect sharing high‑quality architecture insights. Topics include high‑availability, high‑performance, high‑stability architectures, big data, machine learning, Java, system and distributed architecture, AI, and practical large‑scale architecture case studies. Open to ideas‑driven architects who enjoy sharing and learning.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.