Hackforge Academy

Category: spring_boot

Async annotation in Spring Boot

Published on 02 Jun 2026

Explanation

The @Async annotation in Spring Boot is used to execute a method asynchronously in a separate thread. This allows the caller to continue execution without waiting for the method to complete, improving application responsiveness.

Code:

@EnableAsync
@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(
Application.class, args);
    }
}

Explanation

Annotate a method with @Async to run it in a background thread.

Code:

@Service
public class EmailService {

    @Async
    public void sendEmail() {
        System.out.println("
Sending email in background...");
    }
}

Explanation

Methods annotated with @Async can return a CompletableFuture for asynchronous result handling.

Code:

@Async
public CompletableFuture<String> 
processData() {
    return CompletableFuture.
completedFuture("Data Processed");
}

Explanation

Use @Async for long-running tasks such as sending emails, generating reports, processing files, or calling external APIs.

Code:

@Async
public void generateReport() {
    // Long-running report generation
}

Explanation

Without @Async, the caller waits for the method to finish. With @Async, the method runs in a separate thread and the caller continues immediately.

Code:

emailService.sendEmail();
System.out.println("Request completed 
without waiting for email.");

πŸš€ Learn Spring Boot with real-world projects

πŸ’‘ Build REST APIs step by step

🧠 Improve backend development skills

🎯 Get career-ready practical training

Join Our Free WhatsApp Community

Direct access to niche-specific mentors and peers on WhatsApp.

🐍

Python Community

Discuss Django, FastAPI, AI integration, and automation scripts with 15k+ developers.

Join Python Community
βš›οΈ

React Community

Master Next.js, Framer Motion, and State Management. Share your latest UI components.

Join React Community
β˜•

Java Community

Deep dives into Spring Boot, Microservices architecture, and high-performance backend ops.

Join Java Community