Browse Source

screenDaily统计加锁

dev_shibei_match
zxc 4 years ago
parent
commit
2b32df2253
  1. 2
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/NumConstant.java
  2. 2
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/distributedlock/LockConstants.java
  3. 13
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/extract/toscreen/impl/ScreenExtractServiceImpl.java

2
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/NumConstant.java

@ -64,6 +64,8 @@ public interface NumConstant {
long THREE_L = 3L;
long FOUR_L = 4L;
long MINUS_ONE_L = -1L;
long TEN_L = 10L;
long SIX_HUNDRED_L = 600L;
String ZERO_STR = "0";
String ONE_STR = "1";

2
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/distributedlock/LockConstants.java

@ -9,4 +9,6 @@ public interface LockConstants {
String TEST_LOCK_NAME = "testLock";
String STATS_LOCK_NAME = "stats";
String SCREEN_DAILY = "screenDaily";
}

13
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/extract/toscreen/impl/ScreenExtractServiceImpl.java

@ -2,6 +2,8 @@ package com.epmet.service.evaluationindex.extract.toscreen.impl;
import com.alibaba.fastjson.JSON;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.distributedlock.DistributedLock;
import com.epmet.commons.tools.distributedlock.LockConstants;
import com.epmet.commons.tools.enums.EnvEnum;
import com.epmet.commons.tools.utils.DateUtils;
import com.epmet.commons.tools.utils.HttpClientManager;
@ -20,6 +22,7 @@ import com.epmet.service.stats.DimCustomerService;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.redisson.api.RLock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
@ -86,6 +89,8 @@ public class ScreenExtractServiceImpl implements ScreenExtractService {
private FactGridMemberStatisticsDailyService factGridMemberStatisticsDailyService;
@Autowired
private ScreenProjectCategoryGridAndOrgDailyService screenProjectCategoryGridAndOrgDailyService;
@Autowired
private DistributedLock distributedLock;
/**
* @param extractOriginFormDTO
@ -163,6 +168,10 @@ public class ScreenExtractServiceImpl implements ScreenExtractService {
* @date 2020/9/24 10:16 上午
*/
public void extractDaily(String customerId, String dateId, boolean isLast) {
RLock lock = null;
try {
// 锁持有10分钟,等待10s
lock = distributedLock.getLock(LockConstants.SCREEN_DAILY, NumConstant.SIX_HUNDRED_L, NumConstant.TEN_L, TimeUnit.SECONDS);
//等待3个线程执行完毕后再 继续执行下一个客户的 避免死锁
final CountDownLatch latch = new CountDownLatch(NumConstant.FOUR);
threadPool.submit(() -> {
@ -312,6 +321,10 @@ public class ScreenExtractServiceImpl implements ScreenExtractService {
log.error("extractDaily run exception", e);
}
log.info("===== extractDaily method end customerId:{}======",customerId);
}finally {
lock.unlock();
}
}
@Override

Loading…
Cancel
Save