so how to solve this problem? On Mon, Apr 14, 2014 at 10:17 PM, Oleg Kalnichevski <[email protected]> wrote: > On Mon, 2014-04-14 at 17:21 +0800, Li Li wrote: >> I am using http client 4.3. I use PoolingHttpClientConnectionManager >> with many threads. >> but I found one thread hangs on socketRead0(other thread is correct) >> >> netstat -anotp|grep 5872 >> (Not all processes could be identified, non-owned process info >> will not be shown, you would have to be root to see it all.) >> tcp 0 0 192.168.11.181:35251 192.168.11.169:61616 >> ESTABLISHED 5872/java off (0.00/0/0) >> tcp 0 0 192.168.11.181:35252 192.168.11.169:61616 >> ESTABLISHED 5872/java off (0.00/0/0) >> tcp 0 0 49.4.132.244:56035 221.204.231.139:80 >> ESTABLISHED 5872/java off (0.00/0/0) >> tcp 0 0 192.168.11.181:41935 192.168.11.151:2181 >> ESTABLISHED 5872/java off (0.00/0/0) >> >> java stack: >> "Thread-51" prio=10 tid=0x00007f7dfc20d800 nid=0x1846 runnable >> [0x00007f7d5c5c4000] >> java.lang.Thread.State: RUNNABLE >> at java.net.SocketInputStream.socketRead0(Native Method) >> at java.net.SocketInputStream.read(SocketInputStream.java:152) >> at java.net.SocketInputStream.read(SocketInputStream.java:122) >> at >> org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:136) >> at >> org.apache.http.impl.io.SessionInputBufferImpl.read(SessionInputBufferImpl.java:195) >> at >> org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:178) >> at >> org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:200) >> at >> org.apache.http.impl.io.ContentLengthInputStream.close(ContentLengthInputStream.java:103) >> at >> org.apache.http.impl.execchain.ResponseEntityWrapper.streamClosed(ResponseEntityWrapper.java:120) >> at >> org.apache.http.conn.EofSensorInputStream.checkClose(EofSensorInputStream.java:227) >> at >> org.apache.http.conn.EofSensorInputStream.close(EofSensorInputStream.java:174) >> at org.apache.http.util.EntityUtils.consume(EntityUtils.java:88) >> at >> org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:222) >> at >> org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:160) >> at >> org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:136) >> at >> com.founder.httpclientfetcher.HttpClientFetcher.httpGet(HttpClientFetcher.java:464) >> >> I am using 4.3.1 >> <dependency> >> <groupId>org.apache.httpcomponents</groupId> >> <artifactId>httpclient</artifactId> >> <version>4.3.1</version> >> </dependency> >> >> my codes: >> defaultRequestConfig = RequestConfig >> .custom() >> .setCookieSpec(CookieSpecs.BEST_MATCH) >> .setExpectContinueEnabled(true) >> >> .setConnectTimeout(this.getConnectTimeout()) >> .setConnectionRequestTimeout(this.getConnectionRequestTimeout()) >> .setSocketTimeout(this.getReadTimeout()).build(); >> >> HttpClientBuilder builder = HttpClients.custom(); >> >> ConnectionKeepAliveStrategy myStrategy = null; >> HttpClientConnectionManager connManager = null; >> >> Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder >> .<ConnectionSocketFactory> create() >> .register("http", >> PlainConnectionSocketFactory.getSocketFactory()) >> .register("https", >> SSLConnectionSocketFactory.getSocketFactory()) >> .build(); >> connManager = new PoolingHttpClientConnectionManager( >> socketFactoryRegistry, null, new DNSResolverWithCache( >> dnsCache)); >> >> ((PoolingHttpClientConnectionManager) connManager).setMaxTotal(this >> .getMaxTotalConnection()); >> ((PoolingHttpClientConnectionManager) connManager) >> .setDefaultMaxPerRoute(this.getMaxConnectionPerRoute()); >> myStrategy = new ConnectionKeepAliveStrategy() { >> public long getKeepAliveDuration(HttpResponse response, >> HttpContext context) { >> // Honor 'keep-alive' header >> HeaderElementIterator it = new BasicHeaderElementIterator( >> response.headerIterator(HTTP.CONN_KEEP_ALIVE)); >> while (it.hasNext()) { >> HeaderElement he = it.nextElement(); >> String param = he.getName(); >> String value = he.getValue(); >> if (value != null && param.equalsIgnoreCase("timeout")) { >> try { >> return Long.parseLong(value) * 1000; >> } catch (NumberFormatException ignore) { >> } >> } >> } >> return HttpClientFetcher.this.defaultKeepAlive; >> } >> >> }; >> builder.setKeepAliveStrategy(myStrategy); >> client = builder.setConnectionManager(connManager) >> .setProxy(getProxy()) >> .setRetryHandler(new MyHttpRequestRetryHander(retryCount)) >> .setDefaultRequestConfig(defaultRequestConfig) >> .setUserAgent(this.getUserAgent()).build(); >> > > Assuming that this.getReadTimeout() returns a positive value, the read > operation can still block indefinitely if the server keeps on sending > packets often enough to prevent the operation from exceeding the socket > timeout value. > > Oleg > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] >
--------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
