【问题标题】:How to set the maximum number of network connections in Retrofit如何在 Retrofit 中设置最大网络连接数
【发布时间】:2014-12-23 09:33:12
【问题描述】:

我正在查看一些 AQuery 代码here,发现有一种方法可以修改 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 android-networking androidhttpclient aquery


    【解决方案1】:

    例如 Retrofit 中的默认连接数在某种程度上是按需的,即为每个新的Runnable(连接)创建/重用新线程,该Executor 提供给Executor

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

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

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

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

    更多信息请见Executors

    【讨论】:

      猜你喜欢
      • 2015-07-01
      • 2014-07-21
      • 2016-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多