Bird
0
0

You want to improve a Spring Boot app's responsiveness by running multiple independent tasks in parallel. Which approach best uses async processing to achieve this?

hard📝 Application Q15 of 15
Spring Boot - Async Processing
You want to improve a Spring Boot app's responsiveness by running multiple independent tasks in parallel. Which approach best uses async processing to achieve this?
ARun all tasks sequentially in the main thread to avoid thread overhead.
BAnnotate each task method with @Async and return CompletableFuture, then combine results with CompletableFuture.allOf().
CUse @Async but return void from all methods to simplify code.
DCreate new threads manually inside each method without @Async.
Step-by-Step Solution
Solution:
  1. Step 1: Identify best async pattern for parallel tasks

    Using @Async with CompletableFuture allows tasks to run in parallel and return results.
  2. Step 2: Combine results properly

    CompletableFuture.allOf() waits for all async tasks to finish, enabling coordinated processing.
  3. Final Answer:

    Annotate each task method with @Async and return CompletableFuture, then combine results with CompletableFuture.allOf(). -> Option B
  4. Quick Check:

    Parallel async tasks + combine results = A [OK]
Quick Trick: Use @Async + CompletableFuture.allOf() for parallel task coordination [OK]
Common Mistakes:
  • Running tasks sequentially loses async benefits
  • Returning void loses ability to track task completion
  • Manually creating threads ignores Spring Boot async support

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes