Browse Source

增加休眠时间,减少冲突

周箭河 5 years ago
parent
commit
cdd424c958

+ 5 - 4
mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupServiceImpl.java

@@ -12,7 +12,6 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
 import org.apache.commons.lang3.StringUtils;
@@ -397,10 +396,12 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
         if (chargeInfo.getMaxNum() != null) {
             //重试避免人数过多频繁冲突
             boolean flag = false;
+            int max = 100, min = 1;
+            int ran2 = (int) (Math.random() * (max - min) + min);
             for (int i = 1; i <= 100; i++) {
-                int max=10000,min=1;
-                long ran2 = (long) (Math.random()*(max-min)+min);
-                TimeUnit.NANOSECONDS.sleep(ran2);
+                if (i == ran2) {
+                    Thread.sleep(ran2);
+                }
                 chargeInfo = sporadicChargeInfoDao.get(sporadicPayDto.getSporadicId());
                 if (chargeInfo.getMaxNum() != null && chargeInfo.getMaxNum() <= chargeInfo.getPaidNum()) {
                     throw new BizException("活动人数暂时已满,请稍后再试");