zoukankan      html  css  js  c++  java
  • 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();

  • 相关阅读:
    聊聊es6中的解构
    JavaScript 中的面向对象编程
    TypeScript 中的类型保护
    7个你应该知道的 JavaScript 原生错误类型
    使用JavaScript策略模式校验表单
    nodejs如何解决高并发?
    nodejs核心模块有哪些?
    Dungeon Master
    Gold Balanced Lineup
    poj 2513Colored Sticks
  • 原文地址:https://www.cnblogs.com/gkbgy/p/7574553.html
Copyright © 2011-2022 走看看