你可能混淆兩件事情:
對於等待隊列大小:
/** The queue of requests that are actually going out to the network. */
private final PriorityBlockingQueue<Request<?>> mNetworkQueue =
new PriorityBlockingQueue<Request<?>>();
排球使用其本身使用一個PriorityQueue與11
private static final int DEFAULT_INITIAL_CAPACITY = 11;
...
public PriorityQueue() {
this(DEFAULT_INITIAL_CAPACITY, null);
}
默認容量對於最大並行網絡請求一個PriorityBlockingQueue,:
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構造函數進行更改。
謝謝,所以一旦有四個請求正在運行,其他人必須等到他們完成。你能證實這一點嗎? – Bot
是的,但您可以通過調用公共RequestQueue(緩存緩存,網絡網絡,int threadPoolSize) – for3st
來自定義線程池大小,我在這裏調用像'requestQueue.add(jsonObjectRequest);''可以最大化爲'INTEGER.MAX_VALUE 2^32)'但他們都會一直等到他們有機會。這是對的嗎 ? – Bot