Roman Abaev
11/21/2023, 11:00 AMCasey Brooks
11/21/2023, 2:32 PMDavio
11/21/2023, 5:55 PMsuspendCoroutine
? Say I'm making a blocking network call with (for sake of argument) HttpUrlConnection (on JVM version 20 so no virtual threads). Does this mean the coroutine keeps blocking the thread it is running on?
Okay, in this case, since there is nothing else to be done, I assume so. But what about if 2 other coroutines want to do the same thing. Does the scheduler decide itself to suspend one of the running coroutines in favor of the new one?xoangon
11/21/2023, 6:54 PM<http://Dispatchers.IO|Dispatchers.IO>
on a machine with 2 CPUs, you still have access to 64 threads. The Dispatchers.IO documentation says:
It defaults to the limit of 64 threads or the number of cores (whichever is larger)
Davio
11/22/2023, 7:48 AMxoangon
11/22/2023, 8:44 AM<http://Dispatchers.IO|Dispatchers.IO>
yes, you'd have 64 blocked threads and no more available.
However, you can use the CoroutineDispatcher::limitedParallelism function to create your own dispatcher with a different number of backing threadsRoman Abaev
11/22/2023, 10:09 AMCoroutineScheduler
implementation.Davio
11/22/2023, 10:32 AMxoangon
11/22/2023, 11:00 AMDavio
11/22/2023, 4:21 PMxoangon
11/22/2023, 6:16 PMRoman Abaev
11/30/2023, 9:31 AM