问题
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);
回答1:
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
来源:https://stackoverflow.com/questions/27617583/how-to-set-the-maximum-number-of-network-connections-in-retrofit