http超时机制



HttpRequestRetryHandler myRetryHandler = new HttpRequestRetryHandler() {

                @Override
                public boolean retryRequest(IOException exception, int arg1, HttpContext arg2) {
                    if (arg1 >= 3) {
                        return false;
                    }
                    if (exception instanceof InterruptedIOException) {
                        // Timeout
                        return true;
                    }
                    if (exception instanceof UnknownHostException) {
                        // Unknown host
                        return true;
                    }
                    if (exception instanceof ConnectTimeoutException) {
                        // Connection refused
                        return true;
                    }
                    if (exception instanceof SocketTimeoutException) {
                        // Connection refused
                        return true;
                    }
                    if (exception instanceof SSLException) {
                        // SSL handshake exception
                        return false;
                    }
                    return false;
                }
            };

            CloseableHttpClient httpclient = HttpClients.custom().setRetryHandler(myRetryHandler)
                    .setDefaultRequestConfig(globalConfig).setMaxConnTotal(100).build();

原文地址:https://www.cnblogs.com/gkbgy/p/7574553.html