When the connection fails, acquire will immediately throw an exception. You just need to catch the exception
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
When the connection fails, acquire will immediately throw an exception. You just need to catch the exception