java - zookeeper curator 分布式锁,zk服务停了,如何保证业务逻辑的正常处理
天蓬老师
天蓬老师 2017-04-18 09:49:44
0
1
468

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

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

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

各位大神求支招

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

répondre à tous(1)
巴扎黑

Lorsque la connexion échoue, l'acquisition lèvera immédiatement une exception. Il vous suffit d'intercepter l'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
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!