java.lang.IllegalStateException: availableProcessors is already set to [4], rejecting [4]

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/fxbin123/article/details/81809606
基础环境:

jdk8
IntelliJ IDEA 2018.1.6
Elasticsearch 6.1.1
SpringBoot 2.0.2.RELEASE

问题重现:

做redis session 共享,加入以下依赖时引发java.lang.IllegalStateException: availableProcessors is already set to [4], rejecting [4] 异常

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
            <version>2.0.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-pool2</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.session</groupId>
            <artifactId>spring-session-data-redis</artifactId>
            <version>2.0.2.RELEASE</version>
        </dependency>
原因分析

SpringBoot 2.X 的 spring-boot-starter-data-redis 默认是以 lettuce 作为连接池的, 而在 lettuce , elasticsearch transport 中都会依赖netty, 二者的netty 版本不一致,不能够兼容

解决方法:

在SpringBoot 启动类中加入
es.set.netty.runtime.available.processorsfalse

@SpringBootApplication
public class Application {

    public static void main(String[] args) {

        // 设置环境变量,解决Es的netty与Netty服务本身不兼容问题
        System.setProperty("es.set.netty.runtime.available.processors","false");
        SpringApplication.run(Application.class, args);
    }
}

猜你喜欢

转载自blog.csdn.net/fxbin123/article/details/81809606