How could I know what the number of threads Dispatchers.IO is currently using ?
As you can read here Dispatchers.IO
doesn't have own pool of threads, it uses a shared pool. Dispatchers.Default
uses the same pool of threads. There no simple way to get active threads currently used by Dispatchers.IO
. But you can try get thread count inside shared pool of threads.
The common pool of threads is creating inside CommonPool.kt
. It can create own pool or use ForkJoinPool. All threads created in pool have a specific name. So you can find all active thread of shared pool by name.
val threads = Thread.getAllStackTraces().keys.filter {
it.name.startsWith("CommonPool") || it.name.startsWith("ForkJoinPool")
}
threads.size
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With