mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-14 05:42:06 +08:00
RedisLockUtil加锁解锁修复sonar.LocksNotUnlockedCheck
This commit is contained in:
+6
-6
@@ -35,8 +35,8 @@ public class RedisLockUtil {
|
|||||||
public boolean acquireLock(String key) {
|
public boolean acquireLock(String key) {
|
||||||
boolean getLock = false;
|
boolean getLock = false;
|
||||||
try {
|
try {
|
||||||
RLock lock = redissonClient.getLock(key);
|
RLock rLock = redissonClient.getLock(key);
|
||||||
return lock.tryLock(chenfengCacheProperties.getLockWaitTime(), chenfengCacheProperties.getLockTimeout(), TimeUnit.MILLISECONDS);
|
return rLock.tryLock(chenfengCacheProperties.getLockWaitTime(), chenfengCacheProperties.getLockTimeout(), TimeUnit.MILLISECONDS);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("[RedisLockUtil][lock]加锁失败", e);
|
log.error("[RedisLockUtil][lock]加锁失败", e);
|
||||||
return getLock;
|
return getLock;
|
||||||
@@ -54,10 +54,10 @@ public class RedisLockUtil {
|
|||||||
public boolean acquireLock(String key, Integer waitTime, Integer timeout) {
|
public boolean acquireLock(String key, Integer waitTime, Integer timeout) {
|
||||||
boolean getLock = false;
|
boolean getLock = false;
|
||||||
try {
|
try {
|
||||||
RLock lock = redissonClient.getLock(key);
|
RLock rLock = redissonClient.getLock(key);
|
||||||
int wt = ObjectUtil.isNull(waitTime) ? chenfengCacheProperties.getLockWaitTime() : waitTime;
|
int wt = ObjectUtil.isNull(waitTime) ? chenfengCacheProperties.getLockWaitTime() : waitTime;
|
||||||
int to = ObjectUtil.isNull(timeout) ? chenfengCacheProperties.getLockTimeout() : timeout;
|
int to = ObjectUtil.isNull(timeout) ? chenfengCacheProperties.getLockTimeout() : timeout;
|
||||||
return lock.tryLock(wt, to, TimeUnit.MILLISECONDS);
|
return rLock.tryLock(wt, to, TimeUnit.MILLISECONDS);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("[RedisLockUtil][lock]加锁失败", e);
|
log.error("[RedisLockUtil][lock]加锁失败", e);
|
||||||
return getLock;
|
return getLock;
|
||||||
@@ -72,8 +72,8 @@ public class RedisLockUtil {
|
|||||||
*/
|
*/
|
||||||
public void releaseLock(String key) {
|
public void releaseLock(String key) {
|
||||||
try {
|
try {
|
||||||
RLock lock = redissonClient.getLock(key);
|
RLock rLock = redissonClient.getLock(key);
|
||||||
lock.unlock();
|
rLock.unlock();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("[RedisLockUtil][unlock]解锁失败", e);
|
log.error("[RedisLockUtil][unlock]解锁失败", e);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user