zoukankan      html  css  js  c++  java
  • HttpClient中的Timout

    connection timeout和SoTimeout

    A connection timeout occurs only upon starting the TCP connection. This usually happens if the remote machine does not answer. This means that the server has been shut down, you used the wrong IP/DNS name or the network connection to the server is down.

    A socket timeout is dedicated to monitor the continuous incoming data flow. If the data flow is interrupted for the specified timeout the connection is regarded as stalled/broken. Of course this only works with connections where data is received all the time.

    By setting socket timeout to 1 this would require that every millisecond new data is received (assuming that you read the data block wise and the block is large enough)!

    If only the incoming stream stalls for more than a millisecond you are running into a timeout

    代码

    static final PoolingHttpClientConnectionManager httpClientConnectionManager = new PoolingHttpClientConnectionManager();
    
    static HttpClient getClient() {
       RequestConfig requestConfig = RequestConfig.custom()
               .setConnectTimeout(2000)
               .setSocketTimeout(2000)
               .build();
       return HttpClients.custom()
               .setConnectionManager(httpClientConnectionManager)
               .disableAutomaticRetries()
               .setDefaultRequestConfig(requestConfig)
               .build();
    }
    
  • 相关阅读:
    花生壳 manjaro 安装
    manjaro+apache+django+mod_wsgi 安装
    arch linux或 Manjaro下安装 微信 wechat deepin-wine-wechat
    BBU+RRU基本介绍
    黑马python01——基础
    NNLearning阶段性总结01
    【信息论】——第二讲
    10.09——今日文章收集
    pygame安装【在pycharm的IDE project下】
    Git笔记——01
  • 原文地址:https://www.cnblogs.com/weiyinfu/p/6854985.html
Copyright © 2011-2022 走看看