zookeeper curator 分布式锁,zk服务停了,如何保证业务逻辑的正常处理

zookeeper curator 分布式锁,zk服务停了,如何保证业务逻辑的正常处理

InterProcessMutex lock = new InterProcessMutex(client, path);
if (lock.acquire(10 * 1000, TimeUnit.SECONDS)) {
doSth();
}

如果zk连接失败,如何跳过锁判断,执行下面的业务逻辑,不至于业务瘫痪呢

各位大神求支招


胡说叔叔
浏览 581回答 1
1回答

神不在的星期二

当连接失败的时候,acquire会马上抛出异常的,你只要把异常catch住就好public boolean acquire(long time,                       TimeUnit unit)                throws Exception                Acquire the mutex - blocks until it's available or the given time expires. Note: the same thread can call acquire re-entrantly. Each call to acquire that returns true must be balanced by a call to release()Specified by:acquire in interface InterProcessLockParameters:time - time to waitunit - time unitReturns:true if the mutex was acquired, false if notThrows:Exception - ZK errors, connection interruptions
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java