Threads and Coroutines

from the CommonsWare Community archives

At November 10, 2021, 3:56pm, ten asked:

I want to know

  1. Why Coroutines are better than Threads

  2. If I launch 1 lakh Coroutines , these internally choose 1 lakh worker threads right. So where Coroutines are different from Threads

  3. Coroutines use “Concurrency Design Pattern” ,
    What is Concurrency Design Pattern.

Thank you in advance

At November 10, 2021, 4:13pm, mmurphy replied:

I cannot really answer that. That is akin to asking “why green is better than a triangle”. Coroutines, like RxJava, are a layer atop of threads.

Sorry, but I am not completely certain what “lakh” means here (100,000 perhaps?). Coroutines do not map 1:1 to worker threads. See the chapter on dispatchers in Elements of Kotlin Coroutines, a book available as part of your Warescription.

I do not know exactly what you are referring to with that specific quoted phrase, sorry.

At November 17, 2021, 5:05pm, ten replied:

Hello Mark,

I want to start learning “RxJava”.
Could u suggest some resources for learning from the basics.
Thanks in advance

At November 17, 2021, 6:36pm, mmurphy replied:

There is a chapter on RxJava in The Busy Coder’s Guide to Android Development.

Otherwise, I have not looked for RxJava resources in a few years, so I do not have any particular links handy — sorry!