Alexandru Nedelcu
04/23/2023, 5:11 PM<http://Dispatchers.IO|Dispatchers.IO>
being a limited thread-pool, which is odd.
Sample: https://gist.github.com/alexandru/e8ea5e728d77afde4f662b1f7a15ae78
Normally, <http://Dispatchers.IO|Dispatchers.IO>
should be unlimited, if its destination is blocking I/O. This is because, as in the sample, you can end up with thread-starvation, i.e., a situation in which some threads try to wait for something to happen, but it never does, because there are no threads left to execute whatever it is that's waited on.
So why is it limited, and how can it be configured to be unlimited?gildor
04/23/2023, 6:18 PMJoffrey
04/23/2023, 10:09 PMsimon.vergauwen
04/24/2023, 6:12 AMExecutorService
into a dispatcher.
More details: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/as-coroutine-dispatcher.htmlDmitry Khalanskiy [JB]
04/24/2023, 10:08 AMval unlimitedIoDispatcher = <http://Dispatchers.IO|Dispatchers.IO>.limitedParallelism(Int.MAX_VALUE)
and use that throughout instead.
• The recommended approach is to consider the number of threads dedicated to various groups of tasks. At most, a hundred threads for DB connections, 10 threads for file reads, etc. Then, create views with the corresponding numbers of threads using limitedParallelism
.