Questions
KotlinIntermediate4 min
What are Dispatchers and name all of them?
Answer
Dispatchers determine which thread or thread pool a coroutine runs on.
-
Dispatchers.Main
- Thread: The main (UI) thread.
- Use for: UI updates, handling user interactions.
-
Dispatchers.IO
- Thread: A shared pool of on-demand threads (64 or more).
- Use for: Blocking I/O operations (Network, Database, File reading/writing).
-
Dispatchers.Default
- Thread: A shared pool of threads optimized for CPU work (size = number of CPU cores).
- Use for: CPU-intensive tasks (Sorting lists, parsing JSON, complex calculations).
-
Dispatchers.Unconfined
- Thread: Starts in the current thread, but resumes in whatever thread the suspending function finished on.
- Use for: Testing or very specific edge cases. rarely used in general app code.
1:1 Mentorship
Get personalized guidance from a Google Developer Expert. Accelerate your career with dedicated support.
Personalized Learning Path
Mock Interviews & Feedback
Resume & Career Guidance
Share & Help Others
Help fellow developers prepare for interviews
Sharing helps the Android community grow 💚