mirror of
https://github.com/ctripcorp/zeus.git
synced 2024-09-22 00:26:05 +08:00
catch unlock ex
This commit is contained in:
parent
fd1910b11d
commit
846f21ea9b
|
@ -55,7 +55,7 @@ public class MysqlDistLock implements DistLock {
|
|||
DistLockDo d = new DistLockDo().setLockKey(key)
|
||||
.setOwner(Thread.currentThread().getId()).setServer(S.getIp())
|
||||
.setCreatedTime(System.currentTimeMillis());
|
||||
while(System.currentTimeMillis() < end) {
|
||||
while (System.currentTimeMillis() < end) {
|
||||
try {
|
||||
if (tryAddLock(d))
|
||||
return;
|
||||
|
@ -73,7 +73,7 @@ public class MysqlDistLock implements DistLock {
|
|||
.setOwner(Thread.currentThread().getId()).setServer(S.getIp())
|
||||
.setCreatedTime(System.currentTimeMillis());
|
||||
int count = 1;
|
||||
while (true){
|
||||
while (true) {
|
||||
try {
|
||||
if (tryAddLock(d))
|
||||
return;
|
||||
|
@ -86,22 +86,25 @@ public class MysqlDistLock implements DistLock {
|
|||
|
||||
@Override
|
||||
public void unlock() {
|
||||
DistLockDo d = new DistLockDo().setLockKey(key);
|
||||
DalException logEx = null;
|
||||
try {
|
||||
DistLockDo d = new DistLockDo().setLockKey(key);
|
||||
if (unlock(d))
|
||||
return;
|
||||
for (int i = 1; i < MAX_RETRIES; i++) {
|
||||
try {
|
||||
if (unlock(d))
|
||||
return;
|
||||
retryDelay(key, i);
|
||||
} catch (DalException e) {
|
||||
retryDelay(key, i);
|
||||
}
|
||||
}
|
||||
} catch (DalException e) {
|
||||
logger.warn("Fail to unlock the lock " + key);
|
||||
logEx = e;
|
||||
}
|
||||
for (int i = 1; i < MAX_RETRIES; i++) {
|
||||
try {
|
||||
if (unlock(d))
|
||||
return;
|
||||
retryDelay(key, i);
|
||||
} catch (DalException e) {
|
||||
retryDelay(key, i);
|
||||
logEx = e;
|
||||
}
|
||||
}
|
||||
logger.warn("Fail to unlock the lock " + key + ", throwing ex: " + (logEx == null ? " Unknown" : logEx.getMessage()));
|
||||
}
|
||||
|
||||
private boolean tryAddLock(DistLockDo d) throws DalException {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.ctrip.zeus.lock;
|
||||
|
||||
import com.ctrip.zeus.lock.impl.MysqlDistLock;
|
||||
import com.ctrip.zeus.util.S;
|
||||
import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException;
|
||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||
|
|
Loading…
Reference in a new issue