如何在翻新中设置最大网络连接数 [英] How to set the maximum number of network connections in Retrofit

查看:131
本文介绍了如何在翻新中设置最大网络连接数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在此处中浏览了一些AQuery代码发现有一种方法可以修改AQuery中的网络连接数.

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);

推荐答案

在Retrofit中,实例的默认连接数是按需提供的,即为每个新的Runnable(连接)创建/重用新线程到Executor

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

您可以通过限制Thread的数量来限制网络连接.构建RestAdapter时,请执行以下操作:

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

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

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

这与AQuery限制连接数的操作完全相同.

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

有关更多信息,请参见执行器

See Executors for more

这篇关于如何在翻新中设置最大网络连接数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆