> For the complete documentation index, see [llms.txt](https://www.pranaypourkar.co.in/the-programmers-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.pranaypourkar.co.in/the-programmers-guide/spring/spring-features/asynchronous-processing.md).

# Asynchronous Processing

## About

Asynchronous computation in Spring Boot refers to executing tasks or methods asynchronously, meaning they run in the background without blocking the main thread of execution. This allows the main thread to continue processing other tasks while the asynchronous computation runs independently. Asynchronous processing is especially useful for tasks that are time-consuming, such as I/O operations, long-running calculations, or external API calls.

## Ways to Achieve Asynchronous Computation in Spring Boot

### **1. Using `@Async` Annotation**

* The `@Async` annotation is the simplest and most commonly used approach in Spring Boot for asynchronous processing.
* When applied to a method, the method execution is offloaded to a separate thread, freeing the caller to continue with other operations.
* Refer to this Page for more details: [@Async annotation](/the-programmers-guide/spring/spring-features/asynchronous-processing/async-annotation.md)

### **2. Using `CompletableFuture` and `Future`**

* Asynchronous processing can be achieved using `CompletableFuture` or `Future`.
* This allows the caller to retrieve the result of the computation later or handle exceptions.
* Refer to this Page for more details: [ExecutorService](/the-programmers-guide/java/java-concepts/concurrency-and-multithreading/executor-framework/executorservice.md)

### **3. Using `WebFlux` for Reactive Programming**

* Spring WebFlux is part of the Spring ecosystem that enables building non-blocking, reactive applications.
* It uses reactive types like `Mono` and `Flux` to achieve asynchronous processing.
* Refer to this Page for more details: [Reactive Programming](/the-programmers-guide/spring/spring-features/reactive-programming.md)

### **4. Using Project Reactor (`Mono` and `Flux`) without WebFlux**:

* Even if you are not using WebFlux, you can still leverage Project Reactor’s `Mono` and `Flux` for asynchronous, non-blocking processing in your Spring Boot application.
* Refer to this Page for more details: [Project Reactor](/the-programmers-guide/spring/spring-features/reactive-programming/project-reactor.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://www.pranaypourkar.co.in/the-programmers-guide/spring/spring-features/asynchronous-processing.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
