Retrofit中如何设置最大网络连接数

2024-02-12

我正在查看一些 AQuery 代码here https://stackoverflow.com/questions/20488302/aquery-android-query-how-to-load-images-actually发现有一种方法可以修改AQuery中的网络连接数。

有没有办法在改造中做到这一点,改造的默认值是多少?

/* 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

您可以通过限制网络连接数量来限制网络连接Thread。当你建立你的RestAdapter do:

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

or

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

这与 AQuery 限制连接数的做法完全相同。

See 执行者 http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Executors.html了解更多

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Retrofit中如何设置最大网络连接数 的相关文章

随机推荐