错误信息如下:
Exception in thread "main" org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /test
at org.apache.zookeeper.KeeperException.create(KeeperException.java:99)
at org.apache.zookeeper.KeeperException.create(KeeperException.java:51)
at org.apache.zookeeper.ZooKeeper.exists(ZooKeeper.java:1041)
at org.apache.zookeeper.ZooKeeper.exists(ZooKeeper.java:1069)
at cn.zhang.bigdata.zk.ZooKeeperTest.main(ZooKeeperTest.java:11)
网上也说了很多情况:
1、连接还没有创建完成,就操作节点就会报异常?(最多,而且千篇一律,都一样)
2、用最新的jar试一下?(试了不好用)
3、防火墙没有关闭?(我的已经关闭)
但是可能对都会不管用
那么请尝试如下方法:
// 将时间改为 15秒,即可
ZooKeeper zk = new ZooKeeper("10.0.0.11:2181", 15000, null);
这样就可以了