现象: 定义任务不执行了,用jstack 111看线程,发现:
"jobExecutor-3" #47 prio=5 os_prio=0 tid=0x00007f3380016000 nid=0x4053 runnable [0x00007f335eeed000] java.lang.Thread.State: RUNNABLE at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) at java.net.SocketInputStream.read(SocketInputStream.java:171) at java.net.SocketInputStream.read(SocketInputStream.java:141) at sun.security.ssl.InputRecord.readFully(InputRecord.java:465) at sun.security.ssl.InputRecord.read(InputRecord.java:503) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:983) - locked <0x000000068925b648> (a java.lang.Object) at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:940) at sun.security.ssl.AppInputStream.read(AppInputStream.java:105) - locked <0x000000068925b748> (a sun.security.ssl.AppInputStream) at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:160) at org.apache.http.impl.io.SocketInputBuffer.fillBuffer(SocketInputBuffer.java:84) at org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:273) at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:140) at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57) at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:261) at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:283) at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:251) at org.apache.http.impl.conn.ManagedClientConnectionImpl.receiveResponseHeader(ManagedClientConnectionImpl.java:197) at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:272) at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:124) at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:685) at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:487) at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:882) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
很明显,socket读时,死等中。 验证,确实,该url有问题。
修改代码,增加超时设置:
httpClient = new SSLClient(); httpPost = new HttpPost(url); // 超时设置 // ConnectionRequestTimeout,从连接池获取连接的超时时间 // ConnectTimeout,连接服务器的超时时间 // SocketTimeout,传输数据的超时时间,是两个数据包之间的间隔时间,并非整体传输时间。如果一直有数据传输,不会触发此异常。 RequestConfig requestConfig = RequestConfig.custom() .setConnectionRequestTimeout(5000).setConnectTimeout(5000) .setSocketTimeout(10000).build(); httpPost.setConfig(requestConfig);
升级,发现问题依旧。
这段代码之前在http上试验过,是没问题的。 怀疑是https时不好使,google之,得下文:
https://tangjuntc.com/2018/05/18/http-client-ssl-handshake-socket-readtimeout/
说是httpclient的bug,在4.3.5版本已修复, 一看,我用的版本是4.4.1,有点晕~~
继续搜,得下文:
https://issues.apache.org/jira/browse/HTTPCLIENT-1478
得知,修复的不彻底,所以,升级到最新版,
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient --> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.6</version> </dependency>
刚要试,得通知,该URL修复了,晕倒在盒饭上~~
|