截击请求重试策略不考虑超时


11

我已将1500设置为initialTimeoutMsDefaultRetryPolicy,如下所示,但它不考虑超时:

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

花了超过20秒的时间,而我希望在1.5秒后捕获onResponse或onError !!!


我认为,退避后有重试逻辑。因此,请求已发送,在1.5秒后超时,然后在随机时间后重试。总体而言,退休人数为DefaultRetryPolicy.DEFAULT_MAX_RETRIES
Abhishek Ranjan

您对max_tries和backoff_multiplies的值是多少?
卡兰·库拉纳

它们都有默认值。在DefaultRetryPolicy.java中:public static final int DEFAULT_MAX_RETRIES = 1; public static final float DEFAULT_BACKOFF_MULT = 1f;
Alireza Noorali

Answers:



0

使用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));
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.