@@ -17,19 +17,20 @@ import java.util.concurrent.atomic.AtomicInteger
17
17
* then the [Job] of the affected task is [cancelled][Job.cancel] and the task is submitted to the
18
18
* [Dispatchers.IO], so that the affected coroutine can cleanup its resources and promptly complete.
19
19
*
20
- * **NOTE: This API will be replaced in the future**. A different API to create thread-limited thread pools
21
- * that is based on a shared thread-pool and does not require the resulting dispatcher to be explicitly closed
22
- * will be provided, thus avoiding potential thread leaks and also significantly improving performance, due
23
- * to coroutine-oriented scheduling policy and thread-switch minimization.
24
- * See [issue #261](https://github.com/Kotlin/kotlinx.coroutines/issues/261) for details.
20
+ * This is a **delicate** API. The result of this method is a closeable resource with the
21
+ * associated native resources (threads). It should not be allocated in place,
22
+ * should be closed at the end of its lifecycle, and has non-trivial memory and CPU footprint.
23
+ * If you do not need a separate thread-pool, but only have to limit effective parallelism of the dispatcher,
24
+ * it is recommended to use [CoroutineDispatcher.limitedParallelism] instead.
25
+ *
25
26
* If you need a completely separate thread-pool with scheduling policy that is based on the standard
26
27
* JDK executors, use the following expression:
27
28
* `Executors.newSingleThreadExecutor().asCoroutineDispatcher()`.
28
29
* See [Executor.asCoroutineDispatcher] for details.
29
30
*
30
31
* @param name the base name of the created thread.
31
32
*/
32
- @ObsoleteCoroutinesApi
33
+ @DelicateCoroutinesApi
33
34
public fun newSingleThreadContext (name : String ): ExecutorCoroutineDispatcher =
34
35
newFixedThreadPoolContext(1 , name)
35
36
@@ -43,11 +44,12 @@ public fun newSingleThreadContext(name: String): ExecutorCoroutineDispatcher =
43
44
* then the [Job] of the affected task is [cancelled][Job.cancel] and the task is submitted to the
44
45
* [Dispatchers.IO], so that the affected coroutine can cleanup its resources and promptly complete.
45
46
*
46
- * **NOTE: This API will be replaced in the future**. A different API to create thread-limited thread pools
47
- * that is based on a shared thread-pool and does not require the resulting dispatcher to be explicitly closed
48
- * will be provided, thus avoiding potential thread leaks and also significantly improving performance, due
49
- * to coroutine-oriented scheduling policy and thread-switch minimization.
50
- * See [issue #261](https://github.com/Kotlin/kotlinx.coroutines/issues/261) for details.
47
+ * This is a **delicate** API. The result of this method is a closeable resource with the
48
+ * associated native resources (threads). It should not be allocated in place,
49
+ * should be closed at the end of its lifecycle, and has non-trivial memory and CPU footprint.
50
+ * If you do not need a separate thread-pool, but only have to limit effective parallelism of the dispatcher,
51
+ * it is recommended to use [CoroutineDispatcher.limitedParallelism] instead.
52
+ *
51
53
* If you need a completely separate thread-pool with scheduling policy that is based on the standard
52
54
* JDK executors, use the following expression:
53
55
* `Executors.newFixedThreadPool().asCoroutineDispatcher()`.
@@ -56,7 +58,7 @@ public fun newSingleThreadContext(name: String): ExecutorCoroutineDispatcher =
56
58
* @param nThreads the number of threads.
57
59
* @param name the base name of the created threads.
58
60
*/
59
- @ObsoleteCoroutinesApi
61
+ @DelicateCoroutinesApi
60
62
public fun newFixedThreadPoolContext (nThreads : Int , name : String ): ExecutorCoroutineDispatcher {
61
63
require(nThreads >= 1 ) { " Expected at least one thread, but $nThreads specified" }
62
64
val threadNo = AtomicInteger ()
0 commit comments