availableProcessors is already set to [10], rejecting [10]

availableProcessors is already set to [10], rejecting [10]

  • ES low level client 启动时报错
    • 代码
    • 错误信息
    • 原因
    • 解决方案

ES low level client 启动时报错

代码

// ES客户端启动,创建TCP链接
public void init() throws Exception {
	Settings settings = Settings.builder().put("cluster.name", clusterName)
		.put("client.transport.sniff", false)
		.build();
  
    // 运行至这行代码报错!!!
    client = new PreBuiltTransportClient(settings);
    String[] ipPorts = ipPortsStr.split(",");
    for (String ipPort : ipPorts) {
        String[] ipPortArray = ipPort.split(":");
        if (ipPortArray.length != 2) {
            continue;
        }
        client.addTransportAddresses(new TransportAddress(
                InetAddress.getByName(ipPortArray[0]), Integer.parseInt(ipPortArray[1])));
    }
}
  

错误信息

客户端创建TCP链接报错

Caused by: java.lang.IllegalStateException: availableProcessors is already set to [10], rejecting [10]
		at io.netty.util.NettyRuntime$AvailableProcessorsHolder.setAvailableProcessors(NettyRuntime.java:51)
		at io.netty.util.NettyRuntime.setAvailableProcessors(NettyRuntime.java:87)
		at org.elasticsearch.transport.netty4.Netty4Utils.setAvailableProcessors(Netty4Utils.java:83)
		at org.elasticsearch.transport.netty4.Netty4Transport.<init>(Netty4Transport.java:113)
		at org.elasticsearch.transport.Netty4Plugin.lambda$getTransports$0(Netty4Plugin.java:86)
		at org.elasticsearch.client.transport.TransportClient.buildTemplate(TransportClient.java:186)
		at org.elasticsearch.client.transport.TransportClient.<init>(TransportClient.java:280)
		at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:128)
		at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:114)
		at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:104)
		at com.jd.chainet.gateway.config.EsConfiguration.lowLevelEsClient(EsConfiguration.java:85)
		at com.jd.chainet.gateway.config.EsConfiguration$$EnhancerBySpringCGLIB$$5d0ef5eb.CGLIB$lowLevelEsClient$0(<generated>)
		at com.jd.chainet.gateway.config.EsConfiguration$$EnhancerBySpringCGLIB$$5d0ef5eb$$FastClassBySpringCGLIB$$7d6c55be.invoke(<generated>)
		at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
		at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
		at com.jd.chainet.gateway.config.EsConfiguration$$EnhancerBySpringCGLIB$$5d0ef5eb.lowLevelEsClient(<generated>)
		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 org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
		... 110 more

原因

实例化ES客户端时,我们尝试初始化进程的数量。 由于在其他地方使用了Netty且已经初始化,因此实例化失败。

解决方案

在该类中增加静态代码块,禁用ES设置netty进程数的配置。

static {
    System.setProperty("es.set.netty.runtime.available.processors","false");
}

# ES客户端启动,创建TCP链接
public void init() throws Exception {
    # 代码如上,省略
}

你可能感兴趣的:(其他,elasticsearch,java,大数据)