你可能会混淆2件事情:
> wating队列大小
>最大并行网络请求
等待队列大小:
/** The queue of requests that are actually going out to the network. */
private final PriorityBlockingQueue> mNetworkQueue =
new PriorityBlockingQueue>();
Volley使用PriorityBlockingQueue,它本身使用的PriorityQueue的默认容量为11.
private static final int DEFAULT_INITIAL_CAPACITY = 11;
...
public PriorityQueue() {
this(DEFAULT_INITIAL_CAPACITY, null);
}
对于最大并行网络请求:
RequestQueue requestQueue = Volley.newRequestQueue(this);
将会通知
RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network);
这个叫
public RequestQueue(Cache cache, Network network) {
this(cache, network, DEFAULT_NETWORK_THREAD_POOL_SIZE);
}
和DEFAULT_NETWORK_THREAD_POOL_SIZE是
private static final int DEFAULT_NETWORK_THREAD_POOL_SIZE = 4;
因此,默认情况下,有4个并发线程处理请求(所以同时最多4个请求).
TL;博士
训练队列大小11,不能更改;而最大并行网络请求为4,可以使用RequestQueue构造函数进行更改.