Skip to content

Instantly share code, notes, and snippets.

@dvas0004
Last active November 4, 2019 15:55
Show Gist options
  • Save dvas0004/e14374417b99a04fdf22326138290750 to your computer and use it in GitHub Desktop.
Save dvas0004/e14374417b99a04fdf22326138290750 to your computer and use it in GitHub Desktop.
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