spring-boot 2.6.1 ( spring 5.3.13 ) spring-web 2.6.1 kotlinx-coroutines 1.6.0
Since coroutine supports it in spring mvc, it was implemented through the suspend function in the controller. However, requests received through tomcat thread (http-nio-${port}-exec-1) are being answered with tomcat thread (http-nio-${port}-exec-2) when responding.
Did you do this on purpose or is it a bug?
₩₩₩ @RestController class RestContoller{
@PostMapping("/test")
suspend fun test(): ResponseEntity<*> {
log.info("${Thread.currentThread()}") <---- http-nio-port-exec-1
webclient.awaitFirst() <---- suspend non blocking call
log.info("${Thread.currentThread()}") <---- reactor-thread-1
ResponseEntity.ok()
}
} ₩₩₩
When configured like this, the tomcat thread processed at the end of the response is http-nio-port-exec-2 !!
Comment From: mdeinum
That is to be expected as it is what the async request handling in the Servlet API does and that is what is being used under the covers.
Comment From: rstoyanchev
This is expected indeed. Kotlin Coroutines suspending functions are handled through Servlet asynchronous request processing.