Thread pool

This dispatcher has a pool of threads and will start and resume coroutines in any of the threads that are available from that pool. The runtime takes care of determining which thread is available and it also decides how to distribute the load, so there's no work from our side other:

fun main(args: Array<String>) = runBlocking {
val dispatcher = newFixedThreadPoolContext(4, "myPool")

launch(dispatcher) {
println("Starting in ${Thread.currentThread().name}")
delay(500)
println("Resuming in ${Thread.currentThread().name}")
}.join()
}

As seen in the preceding code, a thread pool can be created by using newFixedThreadPoolContext(). The output of the previous code will commonly look as follows:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.165.115