1 回答

TA貢獻(xiàn)1963條經(jīng)驗(yàn) 獲得超6個(gè)贊
當(dāng)連接失敗的時(shí)候,acquire會(huì)馬上拋出異常的,你只要把異常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
添加回答
舉報(bào)