we do not need to create our own threads in Android for any reason?
@Rohit Surwase I don’t see any common reason even without coroutines create own threads on Android if you not a library author (usually you use ThreadPoolExecutor or some high level primitives)
All those cases (1-3) are covered easily by coroutines and provide much better API without drawbacks.
Especially if 1 and 2 have async api
Unfortunately, I have already gone through the docs (1st link) but could not find or understood what I am asking for. I will go through the other link. Thanks so much.
g
gildor
10/09/2018, 6:47 AM
In short:
By default coroutines dispatched in own dedicated thread pool with limited capacity that intended to use only with non-blocking code
For blocking code use special
<http://Dispatcher.IO|Dispatcher.IO>
that creates new thread (by default up to 64) if you have blocking operation
IO and Default dispatchers have different thread limits, but it’s actually more sophisticated, they share single thread pool to be more efficient and share threads.
See details here:
https://github.com/Kotlin/kotlinx.coroutines/issues/261
For UI/Main thread kotlinx.coroutines provides special dispatchers to dispatch work there (see UI guide)
r
Rohit Surwase
10/09/2018, 6:49 AM
Thanks again.
g
gildor
10/09/2018, 6:50 AM
but could not find or understood what I am asking for