TransportClient 开启太多线程

最近公司生产突然崩了,不可用,用jstack查到是:

"elasticsearch[Stick][transport_client_worker][T#8]{New I/O worker #17}" #452 daemon prio=5 os_prio=0 tid=0x0000000034b20800 nid=0x136d0 runnable [0x000000003edfe000]
   java.lang.Thread.State: RUNNABLE
    at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll0(Native Method)
    at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll(WindowsSelectorImpl.java:296)
    at sun.nio.ch.WindowsSelectorImpl$SubSelector.access$400(WindowsSelectorImpl.java:278)
    at sun.nio.ch.WindowsSelectorImpl.doSelect(WindowsSelectorImpl.java:159)
    at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86)
    - locked <0x00000006c69a3040> (a sun.nio.ch.Util$3)
    - locked <0x00000006c69a3030> (a java.util.Collections$UnmodifiableSet)
    - locked <0x00000006c69a1750> (a sun.nio.ch.WindowsSelectorImpl)
    at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
    at org.jboss.netty.channel.socket.nio.SelectorUtil.select(SelectorUtil.java:68)
    at org.jboss.netty.channel.socket.nio.AbstractNioSelector.select(AbstractNioSelector.java:409)
    at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:206)
    at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:90)
    at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178)
    at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
    at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

   Locked ownable synchronizers:
    - <0x00000006c6a29e50> (a java.util.concurrent.ThreadPoolExecutor$Worker)

这种类型的线程有几千个,一直没有找到原因,因为elasticsearch用的都是jpa实现的,后来发现是

TransportClient client = TransportClient.builder().settings(settings).build();

创建的客户端,然后调用搜索,没有显示close的原因。只需在每次使用完,关闭即可:client.close()

你可能感兴趣的:(elasticsearch)