cy
04/03/2017, 12:13 PMval heavyPool = ThreadPoolExecutor(1,
Runtime.getRuntime().availableProcessors(), // or may be number of database connections, etc
1L, TimeUnit.MINUTES,
ArrayBlockingQueue(100) // limit tasks
)
val havyDispatcher = heavyPool.toCoroutineDispatcher()
install(Routing) {
get("/") {
call.respondText("Hello, World!")
}
get("/long-running") {
try {
future(havyDispatcher) {
// do some long running blocking stuff
}.await()
} catch (r: RejectedExecutionException) {
call.respond(HttpStatusCode.ServiceUnavailable)
}
}
}
very simple workaround looks like that, unfortunately it is quantity-based limit, not time-based