if I want to implement the bulkhead pattern in kot...
# coroutines
r
if I want to implement the bulkhead pattern in kotlin, with an old-fashioned blocking http client (OkHttp/feign), what is an idiomatic way to do it in kotlin? A channel with a coroutinecontext backed by a fixed threadpool and ThreadPoolExecutor.AbortPolicy() ?
w
I'm not familiar with bulkhead but if you want to limit the threads used to handle the work then a FixedThreadPool would be the way to go imo
r
I want extra work to be rejected when the thread pool is empty (after queueing for a thread to run on with a configurable timeout)
w
You...want work to be thrown away when your thread pool has no work to do?
s
Other way around. Sounds like they want work to be thrown away when they don't have any open threads to do it.
w
I agree that's likely the intention, but I can't assume, so that's why I asked
d
I would use a number of coroutines equal to the number of threads you want, with a shared Channel of tasks that has a maximum capacity. Then offer tasks to the channel and loop it on the workers.
Schedule it all on the default dispatcher
s
I think in coroutines you would rely on normal backpressure and use a timeout to detect too much work
Have you looked at resilience4j-kotlin ?