Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Maximum Size of the Volley-Library Request-Queue

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);
like image 242
Bot Avatar asked Mar 30 '14 12:03

Bot


People also ask

What is a volley request queue?

The RequestQueue manages worker threads for running the network operations, reading from and writing to the cache, and parsing responses. Requests do the parsing of raw responses and Volley takes care of dispatching the parsed response back to the main thread for delivery.

How can I call multiple requests at the same time in volley?

To achieve it without using any patterns or other libraries, you can mark the request as finished if it responded, and call the method, in each of them, you want to execute if all the requests are finished. On that method, you just need to check if all the requests are done.

Why do we use volley library?

Advantages of Using VolleyAll the tasks that need to be done with Networking in Android, can be done with the help of Volley. Automatic scheduling of network requests. Multiple concurrent network connections. Cancelling request API.

What is RequestQueue?

requestQueue is used to stack your request and handles your cache. You need to create this RequestQueue in your application class or in a Singleton class. Then only you can use the same requestQueue from multiple activities.


1 Answers

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.

like image 165
Patrick Favre Avatar answered Oct 21 '22 21:10

Patrick Favre