🐦 Kotlin Intermediate

What are the main Coroutine Dispatchers in Kotlin?

Answer

Dispatchers determine which thread or thread pool a coroutine runs on. Dispatchers.Main runs on the main/UI thread — use for UI updates. Dispatchers.IO is optimized for I/O-blocking work (network, file, database) and uses a shared pool of up to 64 threads. Dispatchers.Default is for CPU-intensive work (sorting, parsing) and uses a pool sized to the number of CPU cores. Dispatchers.Unconfined runs in whatever thread first calls it — generally avoid this in production. Switch dispatchers with withContext().