springcloud-zookeeper 自带zk版本坑之注册zk服务失败(注册不上)
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-zookeeper-discovery</artifactId></dependency>自带zookeeper:3.5.3-b...
·
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版本
更多推荐
已为社区贡献3条内容
所有评论(0)