Retrofit with Rxjava Schedulers.newThread() vs Schedulers.io()

后端 未结 1 1242
孤独总比滥情好
孤独总比滥情好 2020-12-12 23:13

What are the benefits to use Schedulers.newThread() vs Schedulers.io() in Retrofit network request. I have seen many examples that use

相关标签:
1条回答
  • 2020-12-12 23:52

    You are correct that the benefit of using Schedulers.io() lies in the fact that it uses a thread pool, whereas Schedulers.newThread() does not.

    The primary reason that you should consider using thread pools is that they maintain a number of pre-created threads that are idle and waiting for work. This means that when you have work to be done, you don't need to go through the overhead of creating a thread. Once your work is done, that thread can also be re-used for future work instead of constantly creating and destroying threads.

    Threads can be expensive to create, so minimizing the number of threads that you are creating on the fly is generally good.

    For more information on thread pools, I recommend:

    • What is the use of a Thread pool in Java?
    • What is a thread pool?
    • Thread pool pattern (Wikipedia)
    0 讨论(0)
提交回复
热议问题