mirror of https://gitee.com/y_project/RuoYi.git
feat(all): winlistCaTask 增加耗时统计和CountDownLatch
parent
3beba7e7b2
commit
9027055e7d
|
@ -19,10 +19,12 @@ import com.ruoyi.common.enums.DataSourceType;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StopWatch;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
@ -278,11 +280,20 @@ public class WinLisServiceImpl implements IWinLisService {
|
|||
|
||||
@Override
|
||||
public int winlistCaTask(String testdateLike, Integer limit) {
|
||||
//方法计算执行时间
|
||||
StopWatch sw = new StopWatch();
|
||||
|
||||
AtomicInteger successNum = new AtomicInteger();
|
||||
sw.start("任务1:获取待处理列表");
|
||||
List<LasSapCadataWatingSignVo> watingSignVos = lasSapSampleregService.selectWaitingCaSignList(testdateLike, limit);
|
||||
sw.stop();
|
||||
|
||||
sw.start("任务2:多线程执行任务");
|
||||
CountDownLatch latch = new CountDownLatch(watingSignVos.size()); // 总共等待的任务
|
||||
for (LasSapCadataWatingSignVo vo : watingSignVos) {
|
||||
AtomicInteger i = new AtomicInteger();
|
||||
executorService.execute(() -> {
|
||||
try {
|
||||
log.debug("开始winlistCaTask, index = {}", i.incrementAndGet());
|
||||
String originText = getWinLisCaOriginText(vo.getTestdate(), vo.getMachineid(), vo.getSampleid());
|
||||
CaResultVo caResultVo = generateBjCaInfo(vo.getTestdate(), vo.getMachineid(), vo.getSampleid(), autoSignSignDataId);
|
||||
|
@ -291,8 +302,26 @@ public class WinLisServiceImpl implements IWinLisService {
|
|||
}
|
||||
int result = lasSapSampleregService.insertLasSapCaData(vo, caResultVo);
|
||||
successNum.addAndGet(result);
|
||||
} finally {
|
||||
latch.countDown(); //计数,减1
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
latch.await(); // 等待计数为0后再解除阻塞
|
||||
} catch (Exception e) {
|
||||
log.error("多线程等待异常:" + e.getMessage());
|
||||
}
|
||||
sw.stop();
|
||||
|
||||
log.info("【主线程】所有的任务都到执行,开车走人,去下一个景点购物消费。");
|
||||
log.info("多线程执行winlis补偿签名完成,统计耗时:");
|
||||
log.info(sw.prettyPrint());
|
||||
log.info(sw.getTotalTimeSeconds() + "");
|
||||
log.info(sw.getLastTaskName());
|
||||
log.info(sw.getLastTaskInfo() + "");
|
||||
log.info(sw.getTaskCount() + "");
|
||||
return successNum.get();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue