How to implement an asynchronous REST request to a controller using Springboot?

后端 未结 1 1681
梦如初夏
梦如初夏 2020-12-15 22:41

I\'m trying to implement an asynchronous controller using SprintBoot. I want to make REST request to a controller so that the controller returns immediately, while the work

相关标签:
1条回答
  • 2020-12-15 23:17

    I think you misunderstand the MVC async (and Servlet 3) features. If your controller method takes a long time to complete it will be called in a different thread than the one used to handle the incoming request, but it still has to return data to the client on the same HTTP connection, so it can time out from that point of view. To return immediately but do the processing in the background you don't need async MVC, you just need to do the expensive processing in a background thread (e.g. by calling an @Async method in another @Bean).

    0 讨论(0)
提交回复
热议问题