如何禁用来自重试排球请求? [英] How to disable Volley Request from retrying?

查看:475
本文介绍了如何禁用来自重试排球请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发布JsonRequest到服务器。服务器是缓慢的。凌空往往多次调用缓慢的服务器,因为它没有从第一次请求的响应(因为我的服务器很慢)。有没有办法从重试禁止凌空请求,以便它可以接收的第一反应?

I post a JsonRequest to a server. The server is slow. Volley tends to make multiple calls to the slow server because it didn't get a response from the first request(since my server is slow). Is there any way to disable Volley from retrying a request so that it can receive the first response?

东西我都试过

myRequest.setRetryPolicy(new DefaultRetryPolicy(
                TIMEOUT_MS, 
                RETRIES, 
                BACKOFF_MULT)); 

予有取代TIMEOUT_MS = 0,重试次数= 0和偶数BACKOFF_MULT = 0,但它不工作

I have replace TIMEOUT_MS = 0, RETRIES = 0 and even BACKOFF_MULT = 0 but it doesn't work.

难道你们有什么建议? 感谢并愿意AP preciate任何建议^^

Do you guys have any other suggestions? thanks and would appreciate any suggestions ^^

推荐答案

凌空默认重试策略是:

/** The default socket timeout in milliseconds */
public static final int DEFAULT_TIMEOUT_MS = 2500;

/** The default number of retries */
public static final int DEFAULT_MAX_RETRIES = 1;

/** The default backoff multiplier */
public static final float DEFAULT_BACKOFF_MULT = 1f;

您可以找到它在DefaultRetryPolicy.java,

You can find it in DefaultRetryPolicy.java,

,所以你可以看到,凌空使得1重试请求在默认情况下。

so you can see that volley makes 1 retry request by default.

尝试使用较小的超时时间(如果你不想等待设置在2500ms),或大于设置在2500ms得到的答案),但保留其他的值,例如:

Try to use smaller TIMEOUT (if you don't want to wait the 2500ms), or bigger than 2500ms to get the answer), but keep the other values, for example:

// Wait 20 seconds and don't retry more than once
myRequest.setRetryPolicy(new DefaultRetryPolicy(
       (int) TimeUnit.SECONDS.toMillis(20),
       DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
       DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

这篇关于如何禁用来自重试排球请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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