java面试题网站:www.javaoffers.com

<dependency>
   <groupId>org.springframework.cloud</groupId>
   <artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
</dependency>

自带zookeeper:3.5.3-beta 会出现问题死锁问题,导致zookeeper注册不成功
在这里插入图片描述

3.5.3版出现死锁的zk源码:

public class ClientCnxn {
      public ReplyHeader submitRequest(RequestHeader h, Record request,
        Record response, WatchRegistration watchRegistration,
        WatchDeregistration watchDeregistration)
        throws InterruptedException {
    ReplyHeader r = new ReplyHeader();
    Packet packet = queuePacket(h, r, request, response, null, null, null,
            null, watchRegistration, watchDeregistration);
    synchronized (packet) {
        while (!packet.finished) {
            packet.wait();  //经过大量的测试会出现两种错误:(1)一直等待,(2)直接报错:KeeperException,然后又一直等待。
        }
    }
    return r;
}
}

解决方法:

  <dependency>
   <groupId>org.springframework.cloud</groupId>
   <artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
   <exclusions>
      <!--移除3.5.3-->
      <exclusion>
         <artifactId>zookeeper</artifactId>
         <groupId>org.apache.zookeeper</groupId>
      </exclusion>
   </exclusions>
</dependency>
<!--添加zk3.4.9-->
<dependency>
   <groupId>org.apache.zookeeper</groupId>
   <artifactId>zookeeper</artifactId>
   <version>3.4.9</version>
</dependency>

服务zk器版本为: 3.4.5,建议zk注册不上的可以更换一下zk的版本,移除spring-cloud-zk 自带的zk版本

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐