应该保留多少个Volley请求队列? [英] How many Volley request queues should be maintained?
问题描述
目前,我正在维护一个静态Volley请求队列,如下所述:
Currently I am maintaining one static Volley request queue as described here:
private static RequestQueue mReqQueue;
每个应用程序应该只有一个静态请求队列吗?多于一个有什么害处?例如,如果我只希望一个请求队列来处理Twitter请求,该怎么办?另一个用于身份验证,图像检索等其他功能.
Should there be one and only one static request queue per app? What is the harm in having more than one? for example what if I wanted one request queue just to process twitter requests. And another one for everything else like authentication, image retrieval etc.
推荐答案
我认为Ficus Kirkpatrick在在Volley上的演讲最好只有一个RequestQueue
.
I think Ficus Kirkpatrick said somewhere in his presentation on Volley that optimally, there is only one RequestQueue
.
如果大多数活动,服务和接收者都使用Volley,并且在它们之间进行了很多切换,那么在Application
对象中定义单例RequestQueue
是有意义的,这样您就不必在每个方案/服务/接收器onCreate
中实例化一个新的RequestQueue
.
If most of your activities, services and receivers make use of Volley, and you do a lot of switching between them, it makes sense to define a singleton RequestQueue
in your Application
object so that you don't have to instantiate a new RequestQueue
in every acticity / service / receiver onCreate
.
但是,如果您有很多活动,并且仅在其中一项请求中使用Volley,则最好只在Activity
中定义RequestQueue
,否则它将被实例化.您不使用它的活动.这不应该损害功能,但可以损害内存.
However, if you have a lot of activities, and use Volley in only one of them for one request, then you might be better off defining the RequestQueue
in just that Activity
, or it'll get instantiated in the activities in which you don't use it. This shouldn't hurt functionality, but could hurt memory-wise.
在排球用户组中,Ficus说:
In the volley user group, Ficus said:
RequestQueues非常便宜(大多数只是线程).为了隔离缓存,我们在应用程序中使用了多个.
RequestQueues are pretty cheap (mostly just threads). We use more than one in our app in order to segregate caches.
这告诉我们,如果需要单独的缓存,使用多个RequestQueues
也是一个有效的用例.
Which tells us that it's also a valid use case to use multiple RequestQueues
if you need to have separate caches.
这篇关于应该保留多少个Volley请求队列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!