我使用的是AsyncHttpClient 2.3.0和默认配置。
我注意到,AHC创建了两种类型的线程(从线程转储):
1)
AsyncHttpClient-timer-478-1" - Thread t@30390 java.lang.Thread.State: TIMED_WAITING
at java.lang.Thread.$$YJP$$sleep(Native Method)
at java.lang.Thread.sleep(Thread.java)
at io.netty.util.HashedWheelTimer$Worker.waitForNextTick(HashedWheelTimer.java:560)
at io.netty.util.HashedWheelTimer$Worker.run(HashedWheelTimer.java:459)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)2)
AsyncHttpClient-3-4" - Thread t@20320 java.lang.Thread.State: RUNNABLE
at sun.nio.ch.EPollArrayWrapper.$$YJP$$epollWait(Native Method)
at sun.nio.ch.EPollArrayWrapper.epollWait(EPollArrayWrapper.java)
at sun.nio.ch.EPollArrayWrapper.poll(EPollArrayWrapper.java:269)
at sun.nio.ch.EPollSelectorImpl.doSelect(EPollSelectorImpl.java:93)
at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86)
- locked <16163575> (a io.netty.channel.nio.SelectedSelectionKeySet)
- locked <49280039> (a java.util.Collections$UnmodifiableSet)
- locked <2decd496> (a sun.nio.ch.EPollSelectorImpl)
at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
at io.netty.channel.nio.SelectedSelectionKeySetSelector.select(SelectedSelectionKeySetSelector.java:62)
at io.netty.channel.nio.NioEventLoop.select(NioEventLoop.java:753)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:409)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:886)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)我期望AsyncHttpClient在引擎盖下使用几个线程。但是在运行了几天之后,AsyncHttpClient创建了大约500个AsyncHttpClient线程和一些AsyncHttpClient线程。它被称为不是很密集,也可能也是大约每500次这一时期。只使用executeRequest (执行请求并打开返回的未来) https://static.javadoc.io/org.asynchttpclient/async-http-client/2.3.0/org/asynchttpclient/AsyncHttpClient.html#executeRequest-org.asynchttpclient.Request-org.asynchttpclient.AsyncHandler-
<T> ListenableFuture<T> executeRequest(Request request, AsyncHandler<T> handler);
我看过一个关于连接池配置(https://github.com/AsyncHttpClient/async-http-client/wiki/Connection-pooling)的页面,但没有看到任何关于线程池配置的页面。
这两种类型的线程之间的区别是什么,以及什么会导致大量线程的创建?有什么配置我应该申请吗?
发布于 2019-08-08 20:59:02
AHC有两种类型的线程:
任何不同的数字都意味着您要创建多个客户端。
资料来源: GitHub https://github.com/AsyncHttpClient/async-http-client/issues/1658杂志
https://stackoverflow.com/questions/57414200
复制相似问题