What is the Maximum Size of the Volley-Library Request-Queue
Asked Answered
F

1

13

I am using Volley library in Android, I want to know what is maximum size of queue is allowed using Volley library. There is nothing I found related to this. As I know you need to add the network request to the queue but I don't know what is maximum size of this that I can put it on queue parallel.

RequestQueue requestQueue = Volley.newRequestQueue(this);
.... // block of code
requestQueue.add(jsonObjectRequest);
Facture answered 30/3, 2014 at 12:45 Comment(0)
S
26

You are probably confusing 2 things:

  • wating queue size
  • max parallel network requests

For waiting queue size:

/** The queue of requests that are actually going out to the network. */
private final PriorityBlockingQueue<Request<?>> mNetworkQueue =
    new PriorityBlockingQueue<Request<?>>();

Volley uses a PriorityBlockingQueue which itself uses a PriorityQueue with a initial capacity of 11, but will automatically grow, so there should be no reasonable limit.

private static final int DEFAULT_INITIAL_CAPACITY = 11;
...
public PriorityQueue() {
    this(DEFAULT_INITIAL_CAPACITY, null);
}

For max parallel network requests:

RequestQueue requestQueue = Volley.newRequestQueue(this);

will call

RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network);

and this calls

public RequestQueue(Cache cache, Network network) {
        this(cache, network, DEFAULT_NETWORK_THREAD_POOL_SIZE);
    }

and DEFAULT_NETWORK_THREAD_POOL_SIZE is

private static final int DEFAULT_NETWORK_THREAD_POOL_SIZE = 4;

So by default there are 4 concurrent threads handling the requests (so max 4 request at the same time).


Waiting queue size is Integer.MAX ie. basically limitless; while max parallel network requests are 4, which can be changed with the RequestQueue constructor.

Spam answered 30/3, 2014 at 13:10 Comment(8)
Thanks, so once four requests are running then other have to wait until they finished. can you confirm this also ?Facture
Yes, but you can customize the threadpool size yourself by calling public RequestQueue(Cache cache, Network network, int threadPoolSize)Spam
and I call here like requestQueue.add(jsonObjectRequest); that can be maximum to INTEGER.MAX_VALUE (2^32) but they all will be in waiting until they get a chance . Is it correct ?Facture
I'm sorry I was wrong there upon inspecting the code of the queue the capcity is set to 11 not INTEGER.MAX_VALUE - see my updated answerSpam
Ah, I see thanks :) so more than 11 requests can not add into the queue , right ?Facture
Not tested, but according to the source code: yes :)Spam
Corrent me if I am wrong, or maybe it has been updated. According to recent PriorityBlockingQueue source, the DEFAULT_INITIAL_CAPACITY is just "initial". It will grow automatically as you call request.add() if the queue is already full. Calling the add() will call queue.offer() and queue.tryGrow()Hamfurd
@Hamfurd you are correct, a PriorityBlockingQueue which uses a PriorityQueue is a self growing data structure, I will change my answerSpam

© 2022 - 2024 — McMap. All rights reserved.