How can you enable and use asynchronous methods in a Spring Boot application?

Asynchronous processing in Spring Boot allows long-running tasks to execute in separate threads without blocking the main application flow. This improves responsiveness and throughput, especially for operations such as sending emails, generating reports, or processing notifications.

Key Points

Example

Consider an e-commerce application where an order is placed.

Without Asynchronous Processing

Place Order

↓

Save Order

↓

Send Email

↓

Generate Invoice

↓

Send Notification

↓

Return Response

User waits until all operations complete.

With Asynchronous Processing

Place Order

↓

Save Order

↓

Return Response Immediately

↓

Send Email (Background)

Generate Invoice (Background)

Send Notification (Background)

The user receives a faster response while background tasks continue independently.

Step 1: Enable Asynchronous Processing

Add

@EnableAsync

Example

@SpringBootApplication
@EnableAsync
public class Application {
}

This enables Spring's asynchronous method execution support.

Step 2: Mark Methods with @Async

@Service
public class EmailService {

    @Async
    public void sendWelcomeEmail(
            String email) {

        // Email sending logic
    }
}

Spring executes this method using a separate thread.

Step 3: Return Results if Required

Asynchronous methods can return

Example

@Async
public CompletableFuture<String> processReport() {
    return CompletableFuture.completedFuture(
            "Report Generated");
}

This allows the caller to track progress or retrieve results later.

Step 4: Configure Custom Thread Pool

Default thread configuration may not be suitable for production workloads.

Example

@Bean
public Executor taskExecutor() {

    ThreadPoolTaskExecutor executor =
            new ThreadPoolTaskExecutor();

    executor.setCorePoolSize(5);
    executor.setMaxPoolSize(10);
    executor.setQueueCapacity(50);

    executor.initialize();

    return executor;
}

Benefits

Important Limitation

This will NOT work

@Service
public class EmailService {

    public void registerUser() {
        sendEmail();
    }

    @Async
    public void sendEmail() {
    }
}

Reason

Correct Approach

Common Use Cases

Real-World Example

Banking Application

Customer Transfers Money

↓

Transaction Saved

↓

Response Returned Immediately

↓

SMS Notification Sent Asynchronously

Email Receipt Generated Asynchronously

Best Practices

Interview Tip

A concise interview answer is: To enable asynchronous processing in Spring Boot, use @EnableAsync in the configuration class and annotate methods with @Async. Spring executes these methods in separate threads, improving application responsiveness. For production applications, custom ThreadPoolTaskExecutor configurations are recommended, and @Async methods should be invoked from another Spring-managed bean because self-invocation bypasses Spring proxies.

Last updated: 1 November 2026

Previous question: Explain Spring Boot's approach to handling asynchronous operations.

Next question: You are creating an endpoint in a Spring Boot application that allows users to upload files. Explain how you would handle the file upload and where you would store the files.

More Spring Boot - Level II interview questions

All Spring Boot - Level II questions