java.net.SocketTimeoutException occurred after 1s~3s but my ok http timeout set 10s

Refresh

1 weeks ago

Views

3 time

0

My app is using Retrofit+okhttp. Sometimes, it throw SocketTimeoutException just through 1s~3s after request but my okhttp timeout is setting 10s. It's my code.

 private static OkHttpClient getClient() {
    OkHttpClient client = new OkHttpClient.Builder()
            .connectTimeout(10, TimeUnit.SECONDS)
            .writeTimeout(10, TimeUnit.SECONDS)
            .readTimeout(10, TimeUnit.SECONDS)
            .addInterceptor(headerinterceptor)
            .build();

    return client;
}

public static XXXX XXXX() {
    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(XXXX)
            .addConverterFactory(StatusProcessConverter.create(new GsonBuilder().setLenient().create()))
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .client(getClient())
            .build();

    XXXX methods = retrofit.create(XXXX.class);

    return methods;
}

Can anyone help me ... why the sockettimeout occur less than 10s...

0 answers