> 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](https://www.pranaypourkar.co.in/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](https://www.pranaypourkar.co.in/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](https://www.pranaypourkar.co.in/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](https://www.pranaypourkar.co.in/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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
