官术网_书友最值得收藏!

Coroutine dispatcher

In order to decide what thread to start or resume a coroutine on, a coroutine dispatcher is used. All coroutine dispatchers must implement the CoroutineDispatcher interface:

  • DefaultDispatcher: Currently it is the same as CommonPool. In the future, this may change.
  • CommonPool: Executes and resumes the coroutines in a pool of shared background threads. Its default size makes it optimal for use in CPU-bound operations.
  • Unconfined: Starts the coroutine in the current thread (the thread from which the coroutine was invoked), but will resume the coroutine in any thread. No thread policy is used by this dispatcher.

Along with these dispatchers, there are a couple of builders that can be used to define pools or threads as needed:

  • newSingleThreadContext() to build a dispatcher with a single thread; the coroutines executed here will be started and resumed in the same thread, always.
  • newFixedThreadPoolContext() creates a dispatcher with a pool of threads of the given size. The runtime will decide which thread to use when starting and resuming the coroutines executed in the dispatcher.
主站蜘蛛池模板: 大英县| 锦州市| 榆中县| 宝清县| 清苑县| 聂荣县| 贡嘎县| 景宁| 东兴市| 老河口市| 嘉善县| 新营市| 广水市| 革吉县| 齐河县| 澄江县| 讷河市| 普兰店市| 腾冲县| 巧家县| 永平县| 九龙坡区| 岳阳县| 凭祥市| 黄山市| 昌乐县| 襄垣县| 乐都县| 鹤峰县| 镇宁| 思茅市| 永宁县| 黄梅县| 大冶市| 松桃| 湖口县| 宜州市| 共和县| 林西县| 邵阳县| 门头沟区|