Spring Boot

Async & Scheduling

Async execution with @Async, scheduling with @Scheduled, ThreadPoolTaskExecutor, time management

25 câu hỏi phỏng vấn·
Mid-Level
1

Which annotation makes a method asynchronous in Spring?

Câu trả lời

@Async marks a method for asynchronous execution. Spring executes this method in a separate thread via a TaskExecutor. Requires @EnableAsync on a configuration class to enable the mechanism. Useful for long operations (email sending, file processing) without blocking the main thread. Method can return void, Future or CompletableFuture.

2

Which annotation enables support for @Async methods in Spring?

Câu trả lời

@EnableAsync activates processing of @Async annotations. It must be placed on a @Configuration class. Without this annotation, @Async is ignored and methods execute synchronously.

3

Which legacy return type allows retrieving the result of an @Async method?

Câu trả lời

Future<T> is the historical return type for async methods. Allows retrieving the result via future.get() (blocking). CompletableFuture<T> is now preferred for its functional programming and better composition.

4

What is the main advantage of CompletableFuture over Future for @Async methods?

5

What is AsyncResult used for in Spring?

+22 câu hỏi phỏng vấn

Nắm vững Spring Boot cho lần phỏng vấn tiếp theo

Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.

Bắt đầu miễn phí