【问题标题】:Volley request retry policy doesn't consider timeoutVolley 请求重试策略不考虑超时
【发布时间】:2020-01-11 13:28:55
【问题描述】:

我在 DefaultRetryPolicy 中将 1500 设置为 initialTimeoutMs 如下,但它不考虑超时:

request.setRetryPolicy(new DefaultRetryPolicy(1500
        , DefaultRetryPolicy.DEFAULT_MAX_RETRIES
        , DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

我断开了设备上的 WiFi 以测试它是否超时,我在 Logcat 中看到了这些时间:

2019-12-16 14:28:15.892 I/MyClass: request sent
2019-12-16 14:28:35.930 I/MyClass: request caught onError

我预计在 1.5 秒后捕获 onResponse 或 onError 花了 20 多秒!!!

【问题讨论】:

  • 我相信退避后有重试逻辑。因此请求被发送,在 1.5 秒后超时,然后在随机时间后重试。总的来说,退休的数量是 DefaultRetryPolicy.DEFAULT_MAX_RETRIES
  • max_tries 和 backoff_multiplies 的值是多少?
  • 两者都有默认值。在 DefaultRetryPolicy.java 中:public static final int DEFAULT_MAX_RETRIES = 1;public static final float DEFAULT_BACKOFF_MULT = 1f;

标签: java android android-volley request-timed-out retrypolicy


【解决方案1】:

根据您的配置。你的超时时间应该是 3 秒。 参考http://prasadthangavel.blogspot.com/2013/12/why-volley-android-has-provided-two.html

我认为你应该将 DEFAULT_BACKOFF_MULT 设为零。

【讨论】:

    【解决方案2】:

    使用 5 秒,因为 15 秒用于超时..

    int TIME_OUT = 500; //use 5 sec it will work fine with it..
    
    request.setRetryPolicy(new DefaultRetryPolicy(
        TIME_OUT, 
        DefaultRetryPolicy.DEFAULT_MAX_RETRIES, 
        DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    

    【讨论】:

      猜你喜欢
      • 2016-03-18
      • 1970-01-01
      • 2018-08-19
      • 2015-04-24
      • 2014-12-03
      • 2015-09-30
      • 2021-03-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多