Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/362.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.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 改型onFailure()方法调用数_Java_Retrofit_Okhttp - Fatal编程技术网

Java 改型onFailure()方法调用数

Java 改型onFailure()方法调用数,java,retrofit,okhttp,Java,Retrofit,Okhttp,我正在使用改型,并为远程API调用失败的场景实现了重试逻辑。我从以下线程创建了以下类: onFailure方法是否通过改造执行/调用了5次?为什么呢 public abstract class CallbackWithRetry<T> implements Callback<T> { private static final int TOTAL_RETRIES = 3; private int retryCount = 0; @Overrid

我正在使用改型,并为远程API调用失败的场景实现了重试逻辑。我从以下线程创建了以下类:

onFailure方法是否通过改造执行/调用了5次?为什么呢

public abstract class CallbackWithRetry<T> implements Callback<T> {

    private static final int TOTAL_RETRIES = 3;
    private int retryCount = 0;

    @Override
    public void onFailure(Call<T> call, Throwable t) {
        if (retryCount++ < TOTAL_RETRIES) {
            log.info("Retrying... (" + retryCount + " out of " + TOTAL_RETRIES + ")");
            retry(call);

            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    private void retry(Call<T> call) {
        call.clone().enqueue(this);
    }
}
    call.enqueue(new CallbackWithRetry<String>() {
        @Override
        public void onResponse(Call<String> call, Response<String> response) {
            log.info("Response received from remote API: {}", response.body());
        }
    });
 INFO [OkHttp http://localhost:8081/...] (CallbackWithRetry.java:16) - Retrying... (1 out of 3)
 INFO [OkHttp http://localhost:8081/...] (CallbackWithRetry.java:16) - Retrying... (1 out of 3)
 INFO [OkHttp http://localhost:8081/...] (CallbackWithRetry.java:16) - Retrying... (1 out of 3)
 INFO [OkHttp http://localhost:8081/...] (CallbackWithRetry.java:16) - Retrying... (1 out of 3)
 INFO [OkHttp http://localhost:8081/...] (CallbackWithRetry.java:16) - Retrying... (1 out of 3)

 INFO [OkHttp http://localhost:8081/...] (CallbackWithRetry.java:16) - Retrying... (2 out of 3)
 INFO [OkHttp http://localhost:8081/...] (CallbackWithRetry.java:16) - Retrying... (2 out of 3)
 INFO [OkHttp http://localhost:8081/...] (CallbackWithRetry.java:16) - Retrying... (2 out of 3)
 INFO [OkHttp http://localhost:8081/...] (CallbackWithRetry.java:16) - Retrying... (2 out of 3)
 INFO [OkHttp http://localhost:8081/...] (CallbackWithRetry.java:16) - Retrying... (2 out of 3)

 INFO [OkHttp http://localhost:8081/...] (CallbackWithRetry.java:16) - Retrying... (3 out of 3)
 INFO [OkHttp http://localhost:8081/...] (CallbackWithRetry.java:16) - Retrying... (3 out of 3)
 INFO [OkHttp http://localhost:8081/...] (CallbackWithRetry.java:16) - Retrying... (3 out of 3)
 INFO [OkHttp http://localhost:8081/...] (CallbackWithRetry.java:16) - Retrying... (3 out of 3)
 INFO [OkHttp http://localhost:8081/...] (CallbackWithRetry.java:16) - Retrying... (3 out of 3)