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