As I understood, Maximum number of threads that can be created by Dispatchers.IO is 64, but my result is a little bit tricky.
this is my code.
repeat(500) {
CoroutineScope(Dispatchers.IO).launch {
println(Thread.currentThread().name)
}
}
and this is the result.
...
DefaultDispatcher-worker-18
DefaultDispatcher-worker-46
DefaultDispatcher-worker-17
DefaultDispatcher-worker-47
DefaultDispatcher-worker-69
DefaultDispatcher-worker-64
DefaultDispatcher-worker-66
DefaultDispatcher-worker-67
DefaultDispatcher-worker-68
DefaultDispatcher-worker-41
...
Why is my threadpool count bigger than 64? Does that mean my actual threads was created more than 64?
thank you for reading! please help me
I don't know how Dispachers.IO names it's threads, but I only get 64 coroutines running at a time.
If you want to limit it to the number of CPUs you have you need to set this system property :
kotlinx.coroutines.io.parallelism