Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package com.example.mvc
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController
import java.lang.Thread.sleep
import java.util.concurrent.CompletableFuture
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
@RestController
class Controller {
val worker = {
sleep(1000)
"Done"
}
private val pool : ExecutorService = Executors.newFixedThreadPool(500)
@GetMapping("/asyncTest")
fun asyncTest() : CompletableFuture<String> {
return CompletableFuture.supplyAsync(worker, pool::execute)
}
@GetMapping("/syncTest")
fun syncTest() : String {
return worker()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment