为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

胡说叔叔 2019-03-14 16:15:23
zookeeper curator 分布式锁,zk服务停了,如何保证业务逻辑的正常处理InterProcessMutex lock = new InterProcessMutex(client, path);if (lock.acquire(10 * 1000, TimeUnit.SECONDS)) {doSth();}如果zk连接失败,如何跳过锁判断,执行下面的业务逻辑,不至于业务瘫痪呢各位大神求支招
查看完整描述

1 回答

?
神不在的星期二

TA贡献1963条经验 获得超6个赞

当连接失败的时候,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 InterProcessLock


Parameters:

time - time to wait

unit - time unit


Returns:

true if the mutex was acquired, false if not


Throws:

Exception - ZK errors, connection interruptions


查看完整回答
反对 回复 2019-04-23
  • 1 回答
  • 0 关注
  • 580 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号