今天把一个springboot应用部署到服务器上,启动时报错:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.elasticsearch.client.Client]: Factory method 'client' threw exception; nested exception is java.lang.IllegalStateException: availableProcessors is already set to [8], rejecting [8]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:582)
... 107 more
Caused by: java.lang.IllegalStateException: availableProcessors is already set to [8], rejecting [8]
问题也很奇怪,在我本机IDEA上没问题,部署到测试环境服务器也没问题,怎么一个UAT环境就有问题了呢?两个环境唯一不同的是UAT环境CPU数量比较多,为8核心。网上查了一圈,发现netty项目的github上有报告这个异常:
https://github.com/netty/netty/issues/6956
帖子里说这不是netty的bug,可能是先初始化了netty再初始化Esclient造成的,但感觉不是很有道理,要不然为什么其它环境没问题,偏偏都是8个cpu核心有问题呢?帖子里也给出了临时解决办法,就是加一个启动的jvm参数:
-Des.set.netty.runtime.available.processors=false