2

I was going through some AQuery code here and found there's a way to modify the number of network connections in AQuery.

Is there a way of doing this in retrofit, and what are the default values for retrofit?

/* Settings of Image */
//set the max number of concurrent network connections, default is 4
AjaxCallback.setNetworkLimit(8);

//set the max number of icons (image width <= 50) to be cached in memory, default is 20
BitmapAjaxCallback.setIconCacheLimit(50);

//set the max number of images (image width > 50) to be cached in memory, default is 20
BitmapAjaxCallback.setCacheLimit(50);

aq = new AQuery(context);
Community
  • 1
  • 1
dowjones123
  • 3,695
  • 5
  • 40
  • 83

1 Answers1

3

Default number of connection for instance in Retrofit is somewhat on-demand, i.e new thread is created/reused for each new Runnable (connection) that is fed to the Executor

You can limit network connection by limiting number of Thread. When you build your RestAdapter do:

restAdapterBuilder.setExecutors(Executors.newCachedThreadPool(numberOfConnections), new MainThreadExecutor());

or

restAdapterBuilder.setExecutors(Executors.newFixedThreadPool(numberOfConnections), new MainThreadExecutor());

This is exactly the same what AQuery does to limit the number of connections.

See Executors for more

Nikola Despotoski
  • 49,966
  • 15
  • 119
  • 148