java.lang.IllegalStateException:无法创建子事件循环

时间:2017-02-13 11:57:19

标签: java search elasticsearch

我只是使用Elasticsearch 5.0.0 Java API来搜索索引,然后搜索结果就出来了。但最后问题也出现了。

Exception in thread "main" java.lang.IllegalStateException: failed to create a child event loop
    at io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:88)
    at io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:58)
    at io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:47)
    at io.netty.channel.MultithreadEventLoopGroup.<init>(MultithreadEventLoopGroup.java:58)
    at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:77)
    at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:72)
    at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:59)
    at org.elasticsearch.transport.netty4.Netty4Transport.createBootstrap(Netty4Transport.java:200)
    at org.elasticsearch.transport.netty4.Netty4Transport.doStart(Netty4Transport.java:171)
    at org.elasticsearch.common.component.AbstractLifecycleComponent.start(AbstractLifecycleComponent.java:68)
    at org.elasticsearch.transport.TransportService.doStart(TransportService.java:182)
    at org.elasticsearch.common.component.AbstractLifecycleComponent.start(AbstractLifecycleComponent.java:68)
    at org.elasticsearch.client.transport.TransportClient.buildTemplate(TransportClient.java:169)
    at org.elasticsearch.client.transport.TransportClient.<init>(TransportClient.java:228)
    at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:69)
    at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:65)
    at util.ESUtil.getTransportClient(ESUtil.java:27)
    at core.KKId2KKGeo.convertKKId2KKGeo(KKId2KKGeo.java:57)
    at core.KKId2KKGeo.main(KKId2KKGeo.java:83)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: io.netty.channel.ChannelException: failed to open a new selector
    at io.netty.channel.nio.NioEventLoop.openSelector(NioEventLoop.java:157)
    at io.netty.channel.nio.NioEventLoop.<init>(NioEventLoop.java:148)
    at io.netty.channel.nio.NioEventLoopGroup.newChild(NioEventLoopGroup.java:126)
    at io.netty.channel.nio.NioEventLoopGroup.newChild(NioEventLoopGroup.java:36)
    at io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:84)
... 23 more
Caused by: java.io.IOException: Unable to establish loopback connection
    at sun.nio.ch.PipeImpl$Initializer.run(PipeImpl.java:94)
    at sun.nio.ch.PipeImpl$Initializer.run(PipeImpl.java:61)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.nio.ch.PipeImpl.<init>(PipeImpl.java:171)
    at sun.nio.ch.SelectorProviderImpl.openPipe(SelectorProviderImpl.java:50)
    at java.nio.channels.Pipe.open(Pipe.java:155)
    at sun.nio.ch.WindowsSelectorImpl.<init>(WindowsSelectorImpl.java:127)
    at sun.nio.ch.WindowsSelectorProvider.openSelector(WindowsSelectorProvider.java:44)
    at io.netty.channel.nio.NioEventLoop.openSelector(NioEventLoop.java:155)
... 27 more
Caused by: java.net.SocketException: No buffer space available (maximum connections reached?): connect
    at sun.nio.ch.Net.connect0(Native Method)
    at sun.nio.ch.Net.connect(Net.java:454)
    at sun.nio.ch.Net.connect(Net.java:446)
    at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:648)
    at java.nio.channels.SocketChannel.open(SocketChannel.java:189)
    at sun.nio.ch.PipeImpl$Initializer$LoopbackConnector.run(PipeImpl.java:127)
    at sun.nio.ch.PipeImpl$Initializer.run(PipeImpl.java:76)
... 35 more

我编写的一些代码用于通过ES 5.0.0 java API搜索:

TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
                .addTransportAddress(new      InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
QueryBuilder qb = QueryBuilders.queryStringQuery(d_kkid);
                SearchResponse searchResponse =   client.prepareSearch("kkinfo_index")
                    .setScroll(new TimeValue(60000))
                    .setQuery(qb)
                    .setSize(10).execute().actionGet();

1 个答案:

答案 0 :(得分:0)

我已经解决了我的问题,这是由我编码的不是理由造成的。我的错误代码如下:

for(Object object : object_list){ 
     client = getTransportClient(); 
     //do ES search...
}

原因代码如下:

client = getTransportClient();
for(Object object : object_list){
   // do ES search...
}