diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/common/family/FamilyCommon.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/common/family/FamilyCommon.java index 9aaf5819..4040a189 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/common/family/FamilyCommon.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/common/family/FamilyCommon.java @@ -86,6 +86,8 @@ public class FamilyCommon { private final FamilyMemberTotalExpService familyMemberTotalExpService; private final RedisService redisService; + private static final long BASE_RETRY_INTERVAL = 200L; + private static final int MAX_RETRY = 8; /** * 移除群聊. @@ -134,11 +136,10 @@ public class FamilyCommon { } String lockKey = "family:level:lock:" + member.getFamilyId(); - int maxRetry = 5; int retryCount = 0; boolean lockAcquired = false; - while (retryCount < maxRetry) { + while (retryCount < MAX_RETRY) { try { lockAcquired = redisService.setIfAbsent(lockKey, "1", 30, TimeUnit.SECONDS); @@ -163,8 +164,8 @@ public class FamilyCommon { // 未获取到锁,进行重试 retryCount++; - if (retryCount < maxRetry) { - Thread.sleep(100L * retryCount); + if (retryCount < MAX_RETRY) { + Thread.sleep((long)(BASE_RETRY_INTERVAL * Math.pow(2, retryCount))); } } catch (InterruptedException e) { @@ -198,7 +199,7 @@ public class FamilyCommon { // 重试失败日志 log.error("获取家族升级锁失败,重试{}次后放弃,FamilyId:{},userId:{},exp:{}", - maxRetry, member.getFamilyId(), userId, exp); + MAX_RETRY, member.getFamilyId(), userId, exp); } /**