- Learning Concurrency in Kotlin
- Miguel Angel Castiblanco Torres
- 174字
- 2021-08-05 10:46:45
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.
推薦閱讀
- WildFly:New Features
- Hyper-V 2016 Best Practices
- SpringMVC+MyBatis快速開發與項目實戰
- Mastering Scientific Computing with R
- Julia Cookbook
- Java應用開發技術實例教程
- VMware虛擬化技術
- Learning AngularJS for .NET Developers
- 軟件供應鏈安全:源代碼缺陷實例剖析
- Go語言開發實戰(慕課版)
- Unity 2018 Augmented Reality Projects
- Building Dynamics CRM 2015 Dashboards with Power BI
- Java并發編程之美
- Android應用開發實戰(第2版)
- Arduino電子設計實戰指南:零基礎篇