Issue
I just came across @Async and @EnableAsync annotation and and I understand these are used to handle multiple requests concurrently.
Does that mean spring boot by default handles request synchronously, that mean if request-1 and request-2 calling same API. Then request-2 waits for request-1 to complete. Well I don't that happening in my application, which makes me assume spring boot is by default handles request Asynchronously.
But since we have these annotations. I am confused if spring boot by default Synchronous or Asynchronous .
Solution
Summary
Actually , there is two different programming web model . accroding to your description , i guess that the model you are confused about is springmvc model . it would receive request and handle it in a threa-pool which embeded in spring framkework .
@Async and @EnableAsync
The @Async and @EnableAsync annotations are used to enable asynchronous processing in specific methods or components. By using these annotations, you can make certain methods execute asynchronously, allowing them to run in the background without blocking the main thread. This is particularly useful for handling tasks that can be performed independently of the main request-response cycle.
Spring WebFlux non-blocking model
It since from spring-boot version 3.0 , spring using the non-block request model. It would use less thread to receive request , in general , it would be more stable than traditional request-response thread blocking model. it cost less cpu time , you can read doc here reative in spring
Answered By - Peng
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.