@@ -14,8 +14,19 @@ import kotlin.coroutines.experimental.*
1414 * **NOTE: The resulting [ExecutorCoroutineDispatcher] owns native resources (its thread).
1515 * Resources are reclaimed by [ExecutorCoroutineDispatcher.close].**
1616 *
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+ *
1727 * @param name the base name of the created thread.
1828 */
29+ @ObsoleteCoroutinesApi
1930fun newSingleThreadContext (name : String ): ExecutorCoroutineDispatcher =
2031 newFixedThreadPoolContext(1 , name)
2132
@@ -40,9 +51,20 @@ fun newSingleThreadContext(name: String, parent: Job? = null): CoroutineContext
4051 * **NOTE: The resulting [ExecutorCoroutineDispatcher] owns native resources (its threads).
4152 * Resources are reclaimed by [ExecutorCoroutineDispatcher.close].**
4253 *
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+ *
4364 * @param nThreads the number of threads.
4465 * @param name the base name of the created threads.
4566 */
67+ @ObsoleteCoroutinesApi
4668fun newFixedThreadPoolContext (nThreads : Int , name : String ): ExecutorCoroutineDispatcher {
4769 require(nThreads >= 1 ) { " Expected at least one thread, but $nThreads specified" }
4870 return ThreadPoolDispatcher (nThreads, name)
0 commit comments