fun newFixedThreadPoolContext(nThreads: Int, name: String): ExecutorCoroutineDispatcher

Creates a coroutine execution context with the fixed-size thread-pool and built-in yield support. NOTE: The resulting ExecutorCoroutineDispatcher owns native resources (its threads). Resources are reclaimed by ExecutorCoroutineDispatcher.close.

If the resulting dispatcher is closed and attempt to submit a continuation task is made, then the Job of the affected task is cancelled and the task is submitted to the Dispatchers.IO, so that the affected coroutine can cleanup its resources and promptly complete.

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 issue #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 Executor.asCoroutineDispatcher for details.



the number of threads.


the base name of the created threads.


jvm source
Link copied to clipboard