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

  • 相关阅读:
    MySQL笔记(6)---锁
    MySQL笔记(5)---索引与算法
    MySQL笔记(4)---表
    MySQL笔记(3)---文件
    MySQL笔记(2)---InnoDB存储引擎
    MySQL笔记(1)---MySQL体系结构和存储引擎
    生成器,迭代器,装饰器
    文件操作、def函数、模块导入、json
    数据类型、字符串操作
    基本数据类型,条件判断
  • 原文地址:https://www.cnblogs.com/gkbgy/p/7574553.html
Copyright © 2011-2022 走看看