Does Volley library handles all the request sequentially

纵饮孤独 提交于 2020-01-16 00:43:08

问题


I am using volley library for performing network operation to speed up the things. My Question is that Does Volley executes the requests which have added in the queue sequentially or parallel.

Suppose I add request like Req1, Req2, Req3 , Will they start to run parallel or second request will wait until first finished ??


回答1:


According to the Volley documentation

Volley maintains several network threads. If a thread is not doing anything, then it will take on a job in the queue.

To answer your question, Req1, Req2 and Req3 will each be placed in a worker thread and will run in parallel.

Volley also caches your downloaded data (and determines whether to re-download based on the expire time in the HTTP header of the downloaded data), so if your data doesn't need to be downloaded again, it's fetched from the cache, which is faster than re-downloading.

These are some of the reasons that Volley is proclaimed to be faster than standard network operations for the situations that it's appropriate to use it. You can, of course, implement this yourself, but Google has done a lot of the hard work for you.




回答2:


Usually a queue starts each operation according to the order it was queued, unless it's a priority queue.

Therefore, assuming equal priority (Assuming that the Volley queue is non priority queue), we can conclude that Req1 will get started first. Then Req2, followed by Req3.

However, we can not guarantee the order which each finishes. If Req1 is time consuming, then the requests will finish in a different order than Req1, Req2, Req3.

All we can guarantee is that they will be started in the order Req1, Req2, Req3.



来源:https://stackoverflow.com/questions/22744333/does-volley-library-handles-all-the-request-sequentially

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!