Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用AsyncHttpClient在错误的http代码上实现重试功能?_Java_Android Async Http - Fatal编程技术网

Java 如何使用AsyncHttpClient在错误的http代码上实现重试功能?

Java 如何使用AsyncHttpClient在错误的http代码上实现重试功能?,java,android-async-http,Java,Android Async Http,我需要调用一个url,调用可能会返回错误的http代码,如404、500等。当我遇到这些错误时,我想实现一个重试功能:新的调用将每小时进行一次,最多十次 我使用异步http客户机库来执行POST调用异步 你知道吗 提前感谢您的帮助。该功能值得考虑 API的构造与您想要重试的内容无关,它涉及重试策略、退避、限制重试次数等 如果您使用的是Java7/8,另一种可能性是。e、 g ScheduledExecutorService scheduler = Executors.newSingleThrea

我需要调用一个url,调用可能会返回错误的http代码,如404、500等。当我遇到这些错误时,我想实现一个重试功能:新的调用将每小时进行一次,最多十次

我使用异步http客户机库来执行POST调用异步

你知道吗


提前感谢您的帮助。

该功能值得考虑

API的构造与您想要重试的内容无关,它涉及重试策略、退避、限制重试次数等

如果您使用的是Java7/8,另一种可能性是。e、 g

ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
RetryExecutor executor = new AsyncRetryExecutor(scheduler).
    retryOn(SocketException.class).
    withExponentialBackoff(500, 2).     //500ms times 2 after each retry
    withMaxDelay(10_000).               //10 seconds
    withUniformJitter().                //add between +/- 100 ms randomly
    withMaxRetries(20);