androidengineers.Book a session
โ† All interview questions
KotlinIntermediate4 min

What are Dispatchers and name all of them?

Answer

Dispatchers determine which thread or thread pool a coroutine runs on.

  1. Dispatchers.Main

    • Thread: The main (UI) thread.
    • Use for: UI updates, handling user interactions.
  2. Dispatchers.IO

    • Thread: A shared pool of on-demand threads (64 or more).
    • Use for: Blocking I/O operations (Network, Database, File reading/writing).
  3. 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).
  4. 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.

Mark this when you can explain the answer in your own words.

Share & Help Others

Help fellow developers prepare for interviews

Sharing helps the Android community grow ๐Ÿ’š

Keep practising