Parallel HTTP requests with Retrofit

前端 未结 1 1701
Happy的楠姐
Happy的楠姐 2020-12-14 02:27

I have an Android application that is currently using Volley library to make network requests and show downloaded images with NetworkImageView.

相关标签:
1条回答
  • 2020-12-14 03:00

    Retrofit uses an Executor for queueing requests.

    The default uses Executors.newCachedThreadPool which allows for unlimited threads. This fits most use cases since normally you would only ever have one or two requests happening at once.

    You can change this behavior, however, by supplying your own when building the RestAdapter. Call setExecutors and pass in an executor that uses a confined thread pool (limited to whatever number you would like). For the second argument, simply pass a new instance of MainThreadExecutor so that callbacks happen on the main thread.

    0 讨论(0)
提交回复
热议问题