Http fluent API引发的线程未能结束

表现是线上机器线程很多,jstack一下都是:

Http fluent API引发的线程未能结束
 1 "pool-8-thread-47" prio=10 tid=0x00007f2930534800 nid=0x63ed waiting on condition [0x000000004969c000]
 2    java.lang.Thread.State: WAITING (parking)
 3         at sun.misc.Unsafe.park(Native Method)
 4         - parking to wait for  <0x00000000a320eb68> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
 5         at java.util.concurrent.locks.LockSupport.park(LockSupport.java:156)
 6         at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:1987)
 7         at org.apache.http.pool.PoolEntryFuture.await(PoolEntryFuture.java:133)
 8         at org.apache.http.pool.AbstractConnPool.getPoolEntryBlocking(AbstractConnPool.java:282)
 9         at org.apache.http.pool.AbstractConnPool.access$000(AbstractConnPool.java:64)
10         at org.apache.http.pool.AbstractConnPool$2.getPoolEntry(AbstractConnPool.java:177)
11         at org.apache.http.pool.AbstractConnPool$2.getPoolEntry(AbstractConnPool.java:170)
12         at org.apache.http.pool.PoolEntryFuture.get(PoolEntryFuture.java:102)
13         at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.leaseConnection(PoolingHttpClientConnectionManager.java:240)
14         at org.apache.http.impl.conn.PoolingHttpClientConnectionManager$1.get(PoolingHttpClientConnectionManager.java:227)
15         at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:172)
16         at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:194)
17         at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:85)
18         at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
19         at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186)
20         at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
21         at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106)
22         at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
23         at org.apache.http.client.fluent.Request.execute(Request.java:143)
24         at com.alibaba.xx.xx.xx.impl.EventManagerImpl$3.run(EventManagerImpl.java:164)
25         at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
26         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
27         at java.lang.Thread.run(Thread.java:662)
Http fluent API引发的线程未能结束

关键锁在了标红的语句,进去看了下是Http内部缓存池拿光了连接数。

原因:

1 org.apache.http.client.fluent.Request.Post(requestURL)
2                                 .connectTimeout(250)
3                                 .socketTimeout(500)7                                 .execute().returnContent();

问题出在当时认为这个请求我不关心返回,就直接没有加上return方法。这样导致了InputStream一直没能释放。

Http fluent API引发的线程未能结束,布布扣,bubuko.com

Http fluent API引发的线程未能结束

上一篇:50个C/C++源代码网站


下一篇:Java经典案例之-“最大公约数和最小公倍数”