Difference between usage of Dispatcher IO and Default

前端 未结 2 1382
孤街浪徒
孤街浪徒 2021-02-04 02:44

In this question: Kotlin Coroutines choosing Dispatcher we can understand to use Dispatcher.Default on CPU process, like an image/video conversion and Dispatc

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-04 03:22

    The difference is that Dispatchers.Default is limited to the number of CPU cores (with a minimum of 2) so only N (where N == cpu cores) tasks can run in parallel in this dispatcher.

    On the IO dispatcher there are by default 64 threads, so there could be up to 64 parallel tasks running on that dispatcher.

    The idea is that the IO dispatcher spends a lot of time waiting (IO blocked), while the Default dispatcher is intended for CPU intensive tasks, where there is little or no sleep.

提交回复
热议问题