Read time out

fatsunwood 发布于 2016/01/04 15:22
阅读 471
收藏 0

解读下一代网络:算力网络正从理想照进现实!>>>

线上的环境调用第三方的接口时,报出java.net.SocketTimeoutException: Read timed out异常。比例大概5%

           

 SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
                        public boolean isTrusted(X509Certificate[] chain,
                                String authType) throws CertificateException {
                            return true;
                        }
                    }).build();
            SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
                    sslContext);
            return HttpClients.custom().setSSLSocketFactory(sslsf).setDefaultRequestConfig(
                        RequestConfig.custom().setConnectTimeout(timeout).setSocketTimeout(timeout).setConnectionRequestTimeout(timeout).build()
            ).build();



            HttpPost post = new HttpPost(url);




        // 设置请求的数据及数据编码
        StringEntity reqEntity = new StringEntity(new String(xmlData.getBytes()), charset);
        post.setEntity(reqEntity);
        post.setHeader("Content-Type", "text/xml;charset=iso-8859-1");
        // 发送请求
        HttpResponse response = client.execute(post);



Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:152)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at sun.security.ssl.InputRecord.readFully(InputRecord.java:442)
at sun.security.ssl.InputRecord.read(InputRecord.java:480)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:934)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1359)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1343)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:394)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:353)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:134)
... 77 more



加载中
0
FeiFeiZheng
FeiFeiZheng

这个是超过一定时间对方没有处理完返回响应造成的。

可以增大超时时间试试。 最好还是找接口对方看一下,评估一下这个时间设置多少合适。

另外也有可能是对方的问题,比如存在死锁,业务逻辑存在问题等因素,都可能导致没有及时给出响应。

返回顶部
顶部