public class ThreadPoolDispatcherKt
| Modifier and Type | Method and Description |
|---|---|
static ExecutorCoroutineDispatcher |
newFixedThreadPoolContext(int nThreads,
java.lang.String name)
Creates new coroutine execution context with the fixed-size thread-pool and built-in
YieldKt.yield support.
NOTE: The resulting class ExecutorCoroutineDispatcher owns native resources (its threads).Resources are reclaimed by ExecutorCoroutineDispatcher.close. |
static ExecutorCoroutineDispatcher |
newSingleThreadContext(java.lang.String name)
Creates a new coroutine execution context using a single thread with built-in
YieldKt.yield support.
NOTE: The resulting class ExecutorCoroutineDispatcher owns native resources (its thread).Resources are reclaimed by ExecutorCoroutineDispatcher.close. |
public static ExecutorCoroutineDispatcher newSingleThreadContext(java.lang.String name)
Creates a new coroutine execution context using a single thread with built-in YieldKt.yield support.
NOTE: The resulting class ExecutorCoroutineDispatcher owns native resources (its thread).Resources are reclaimed by ExecutorCoroutineDispatcher.close.
NOTE: This API will be replaced in the future. A different API to create thread-limited thread pools
that is based on a shared thread-pool and does not require the resulting dispatcher to be explicitly closed
will be provided, thus avoiding potential thread leaks and also significantly improving performance, due
to coroutine-oriented scheduling policy and thread-switch minimization.
See https://github.com/Kotlin/kotlinx.coroutines/issues/261 for details.
If you need a completely separate thread-pool with scheduling policy that is based on the standard
JDK executors, use the following expression:
Executors.newSingleThreadExecutor().asCoroutineDispatcher().
See ExecutorsKt.from for details.
name - the base name of the created thread.YieldKt.yield,
class ExecutorCoroutineDispatcher,
ExecutorCoroutineDispatcher.close,
https://github.com/Kotlin/kotlinx.coroutines/issues/261,
ExecutorsKt.frompublic static ExecutorCoroutineDispatcher newFixedThreadPoolContext(int nThreads, java.lang.String name)
Creates new coroutine execution context with the fixed-size thread-pool and built-in YieldKt.yield support.
NOTE: The resulting class ExecutorCoroutineDispatcher owns native resources (its threads).Resources are reclaimed by ExecutorCoroutineDispatcher.close.
NOTE: This API will be replaced in the future. A different API to create thread-limited thread pools
that is based on a shared thread-pool and does not require the resulting dispatcher to be explicitly closed
will be provided, thus avoiding potential thread leaks and also significantly improving performance, due
to coroutine-oriented scheduling policy and thread-switch minimization.
See https://github.com/Kotlin/kotlinx.coroutines/issues/261 for details.
If you need a completely separate thread-pool with scheduling policy that is based on the standard
JDK executors, use the following expression:
Executors.newFixedThreadPool().asCoroutineDispatcher().
See ExecutorsKt.from for details.
nThreads - the number of threads.name - the base name of the created threads.YieldKt.yield,
class ExecutorCoroutineDispatcher,
ExecutorCoroutineDispatcher.close,
https://github.com/Kotlin/kotlinx.coroutines/issues/261,
ExecutorsKt.from