Ankit Kumar
05/17/2024, 6:48 PMDispatchers.IO.limitedParallelism(64)
OR
System.setProperty(IO_PARALLELISM_PROPERTY_NAME, 50.toString())
Is it just 1st one will limit for anyone using the dispatcher instance created
and 2nd one will always set the limit of each time we create a dispatcher instance
Can someone share more insights on thisRiccardo Lippolis
05/18/2024, 7:43 AMDispatchers.IO.limitedParallelism(4)
returns a dispatcher that uses the IO dispatcher, but runs at most 4 coroutines at the same time. Of course the number of parallelism could never be higher than the number of threads in the original Dispatcher (e.g. a single-threaded dispatcher with a parallelism of 4 makes no sense). Note that calling this function does not change the original dispatcher (IO in this case).
The IO_PARALLELISM_PROPERTY_NAME sets the system-wide maximum number of threads used by <http://Dispatchers.IO|Dispatchers.IO>
, so that applies to the IO dispatcher itself. Note that this is a JVM property only, if I am not mistaken.