Spring Boot

Async & Scheduling

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

25 面接問題·
Mid-Level
1

Which annotation makes a method asynchronous in Spring?

回答

@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?

回答

@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?

回答

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 面接問題

次の面接に向けてSpring Bootをマスター

すべての問題、flashcards、技術テスト、コードレビュー演習、面接シミュレーターにアクセス。

無料で始める