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();

posted @ 2017-09-22 14:01  bod08gongyu  阅读(542)  评论(0编辑  收藏  举报