Browse Source

线程数量控制

master
jianjun 5 years ago
parent
commit
e7db73a2b5
  1. 13
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/FactOriginExtractController.java
  2. 2
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/extract/dataToIndex/impl/IndexOriginExtractServiceImpl.java
  3. 19
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/extract/todata/impl/FactOriginExtractServiceImpl.java

13
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/FactOriginExtractController.java

@ -5,7 +5,6 @@ import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.dto.extract.form.ExtractFormDTO;
import com.epmet.service.evaluationindex.extract.todata.*;
import com.epmet.util.DimIdGenerator;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
@ -13,7 +12,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
import java.util.List;
/**
@ -45,14 +44,12 @@ public class FactOriginExtractController {
@PostMapping("extractall")
public Result extractAll(@RequestBody ExtractFormDTO extractFormDTO) {
if (StringUtils.isNotBlank(extractFormDTO.getStartDate()) && StringUtils.isNotBlank(extractFormDTO.getEndDate())) {
Date startDate = DateUtils.stringToDate(extractFormDTO.getStartDate(), "yyyyMMdd");
Date endDate = DateUtils.stringToDate(extractFormDTO.getEndDate(), "yyyyMMdd");
do {
String dateDimId = DimIdGenerator.getDateDimId(startDate);
List<String> daysBetween = DateUtils.getDaysBetween(extractFormDTO.getStartDate(), extractFormDTO.getEndDate());
for (int i = 0; i < daysBetween.size(); i++) {
String dateDimId = daysBetween.get(i);
extractFormDTO.setDateId(dateDimId);
factOriginExtractService.extractAll(extractFormDTO);
startDate = DateUtils.addDateDays(DateUtils.stringToDate(extractFormDTO.getStartDate(), "yyyyMMdd"), 1);
} while (endDate.compareTo(startDate) >= 0);
}
} else {
factOriginExtractService.extractAll(extractFormDTO);
}

2
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/extract/dataToIndex/impl/IndexOriginExtractServiceImpl.java

@ -27,7 +27,7 @@ import java.util.concurrent.*;
public class IndexOriginExtractServiceImpl implements IndexOriginExtractService {
ThreadFactory namedThreadFactory = new ThreadFactoryBuilder()
.setNameFormat("indexOriginExtract-pool-%d").build();
ExecutorService threadPool = new ThreadPoolExecutor(2, 8,
ExecutorService threadPool = new ThreadPoolExecutor(1, 1,
10L, TimeUnit.MINUTES,
new LinkedBlockingQueue<>(500), namedThreadFactory, new ThreadPoolExecutor.CallerRunsPolicy());

19
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/extract/todata/impl/FactOriginExtractServiceImpl.java

@ -27,7 +27,7 @@ import java.util.concurrent.*;
public class FactOriginExtractServiceImpl implements FactOriginExtractService {
ThreadFactory namedThreadFactory = new ThreadFactoryBuilder()
.setNameFormat("factOriginExtract-pool-%d").build();
ExecutorService threadPool = new ThreadPoolExecutor(4, 8,
ExecutorService threadPool = new ThreadPoolExecutor(1, 1,
10L, TimeUnit.MINUTES,
new LinkedBlockingQueue<>(500), namedThreadFactory, new ThreadPoolExecutor.CallerRunsPolicy());
@ -53,13 +53,14 @@ public class FactOriginExtractServiceImpl implements FactOriginExtractService {
List<String> customerIds = new ArrayList<>();
if (StringUtils.isNotBlank(customerId)) {
customerIds.add(customerId);
}
int pageNo = NumConstant.ONE;
int pageSize = NumConstant.ONE_HUNDRED;
customerIds = dimCustomerService.selectCustomerIdPage(pageNo, pageSize);
if (CollectionUtils.isEmpty(customerIds)) {
log.error("extractAll 获取客户Id为空");
return;
} else {
int pageNo = NumConstant.ONE;
int pageSize = NumConstant.ONE_HUNDRED;
customerIds = dimCustomerService.selectCustomerIdPage(pageNo, pageSize);
if (CollectionUtils.isEmpty(customerIds)) {
log.error("extractAll 获取客户Id为空");
return;
}
}
String finalDateId = dateId;
@ -67,7 +68,7 @@ public class FactOriginExtractServiceImpl implements FactOriginExtractService {
ExtractFormDTO param = new ExtractFormDTO();
param.setCustomerId(cId);
param.setDateId(finalDateId);
// log.warn();
log.debug("extractAll param:{}", JSON.toJSONString(param));
submitJob(param);
});

Loading…
Cancel
Save