• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3  */
4 
5 package kotlinx.coroutines
6 
7 /**
8  * The [CoroutineDispatcher] that is designed for offloading blocking IO tasks to a shared pool of threads.
9  * Additional threads in this pool are created on demand.
10  * Default IO pool size is `64`; on JVM it can be configured using JVM-specific mechanisms,
11  * please refer to `Dispatchers.IO` documentation on JVM platform.
12  *
13  * ### Elasticity for limited parallelism
14  *
15  * `Dispatchers.IO` has a unique property of elasticity: its views
16  * obtained with [CoroutineDispatcher.limitedParallelism] are
17  * not restricted by the `Dispatchers.IO` parallelism. Conceptually, there is
18  * a dispatcher backed by an unlimited pool of threads, and both `Dispatchers.IO`
19  * and views of `Dispatchers.IO` are actually views of that dispatcher. In practice
20  * this means that, despite not abiding by `Dispatchers.IO`'s parallelism
21  * restrictions, its views share threads and resources with it.
22  *
23  * In the following example
24  * ```
25  * // 100 threads for MySQL connection
26  * val myMysqlDbDispatcher = Dispatchers.IO.limitedParallelism(100)
27  * // 60 threads for MongoDB connection
28  * val myMongoDbDispatcher = Dispatchers.IO.limitedParallelism(60)
29  * ```
30  * the system may have up to `64 + 100 + 60` threads dedicated to blocking tasks during peak loads,
31  * but during its steady state there is only a small number of threads shared
32  * among `Dispatchers.IO`, `myMysqlDbDispatcher` and `myMongoDbDispatcher`
33  */
34 @Suppress("EXTENSION_SHADOWED_BY_MEMBER")
35 public expect val Dispatchers.IO: CoroutineDispatcher
36 
37 
38