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

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.
主站蜘蛛池模板: 泌阳县| 临漳县| 孟村| 阳朔县| 景宁| 扎兰屯市| 方城县| 海原县| 西城区| 新巴尔虎左旗| 牡丹江市| 福鼎市| 蒙城县| 南和县| 承德县| 旬阳县| 牙克石市| 海门市| 霍城县| 治县。| 晋江市| 永定县| 延川县| 星子县| 莎车县| 安陆市| 衡东县| 温泉县| 句容市| 马尔康县| 抚州市| 贵阳市| 当阳市| 鄂托克前旗| 莱西市| 蒙自县| 吴桥县| 宁津县| 江达县| 曲阳县| 和顺县|