top of page

Don’t Run Blocking Operations Using Dispatchers.Default!

Updated: Sep 23




The Dispatchers.Default dispatcher is optimized for CPU-bound tasks, which means it's perfect for tasks like complex calculations that don't involve waiting (e.g., blocking I/O). However, blocking the Dispatchers.Default thread pool can be risky, as it could delay or freeze other coroutines that need to run.


Dispatchers.Default can only provide as many threads as you have cores on your device. That means if you have a 2-core device you will only have 2 threads available for parallel execution. If you block them - you're out of luck.


I built this example where I run blocking operations (blocking the thread for 5 seconds) using Dispatchers.Default. What happens here is it ties up available threads, causing other coroutines on the same dispatcher to be delayed.


✅ For blocking operations, use Dispatchers.IO, which is designed for blocking I/O tasks like file or network operations. This will prevent blocking CPU-optimized threads and ensure your app stays responsive.

9 views0 comments

Comments


bottom of page