@@ -14,8 +14,19 @@ import kotlin.coroutines.experimental.*
14
14
* **NOTE: The resulting [ExecutorCoroutineDispatcher] owns native resources (its thread).
15
15
* Resources are reclaimed by [ExecutorCoroutineDispatcher.close].**
16
16
*
17
+ * **NOTE: This API will be replaced in the future**. A different API to create thread-limited thread pools
18
+ * that is based on a shared thread-pool and does not require the resulting dispatcher to be explicitly closed
19
+ * will be provided, thus avoiding potential thread leaks and also significantly improving performance, due
20
+ * to coroutine-oriented scheduling policy and thread-switch minimization.
21
+ * See [issue #261](https://github.com/Kotlin/kotlinx.coroutines/issues/261) for details.
22
+ * If you need a completely separate thread-pool with scheduling policy that is based on the standard
23
+ * JDK executors, use the following expression:
24
+ * `Executors.newSingleThreadExecutor().asCoroutineDispatcher()`.
25
+ * See [Executor.asCoroutineDispatcher] for details.
26
+ *
17
27
* @param name the base name of the created thread.
18
28
*/
29
+ @ObsoleteCoroutinesApi
19
30
fun newSingleThreadContext (name : String ): ExecutorCoroutineDispatcher =
20
31
newFixedThreadPoolContext(1 , name)
21
32
@@ -40,9 +51,20 @@ fun newSingleThreadContext(name: String, parent: Job? = null): CoroutineContext
40
51
* **NOTE: The resulting [ExecutorCoroutineDispatcher] owns native resources (its threads).
41
52
* Resources are reclaimed by [ExecutorCoroutineDispatcher.close].**
42
53
*
54
+ * **NOTE: This API will be replaced in the future**. A different API to create thread-limited thread pools
55
+ * that is based on a shared thread-pool and does not require the resulting dispatcher to be explicitly closed
56
+ * will be provided, thus avoiding potential thread leaks and also significantly improving performance, due
57
+ * to coroutine-oriented scheduling policy and thread-switch minimization.
58
+ * See [issue #261](https://github.com/Kotlin/kotlinx.coroutines/issues/261) for details.
59
+ * If you need a completely separate thread-pool with scheduling policy that is based on the standard
60
+ * JDK executors, use the following expression:
61
+ * `Executors.newFixedThreadPool().asCoroutineDispatcher()`.
62
+ * See [Executor.asCoroutineDispatcher] for details.
63
+ *
43
64
* @param nThreads the number of threads.
44
65
* @param name the base name of the created threads.
45
66
*/
67
+ @ObsoleteCoroutinesApi
46
68
fun newFixedThreadPoolContext (nThreads : Int , name : String ): ExecutorCoroutineDispatcher {
47
69
require(nThreads >= 1 ) { " Expected at least one thread, but $nThreads specified" }
48
70
return ThreadPoolDispatcher (nThreads, name)
0 commit comments