How to make sure Spring Kotlin and Coroutines are properly configured

26 views Asked by At

I just created a simple example to test out spring with Kotlins coroutine and webflux. But I am not sure if I just didnt understand what exactly spring is doing with these coroutines or I havent configured it properly.

Here is the code

@RestController
class Controller{
    @GetMapping("/a")
    suspend fun a(){
        sleep(10000)
        println("called a")
    }

    @GetMapping("/b")
    suspend fun b() {
        println("called b")
    }
}

my gradle dependencies look as follows:

    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core")
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactive")
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor")
    implementation("org.springframework.boot:spring-boot-starter-webflux")
    implementation("org.springframework.boot:spring-boot-starter-data-r2dbc")
    implementation("io.r2dbc:r2dbc-h2")
    implementation 'com.fasterxml.jackson.module:jackson-module-kotlin'
    implementation 'org.jetbrains.kotlin:kotlin-reflect'
    runtimeOnly 'org.postgresql:postgresql'

My understanding is that, when I call a() then for 10 seconds the application should be blocked and calling b() in these 10 seconds wouldn't return anything. But in this case b() still return immediately and prints the text.

So what is the difference to the classical model (one thread per request), when it still can process parallel request without problems? What exactly is the function a() blocking for 10 seconds?

0

There are 0 answers