多线程开启组装数据,对所有非事务操作前置
【摘要】 场景:主流程在历史业务下,越来越繁琐,臃肿,不得不加一堆校验和组装数据,主流程下对多个主表数据操作,记录完本地数据后,调用rpc。高峰调用TP95改造思路:多线程开启组装数据,对所有非事务操作前置,对大事务拆分,减少重复查询数据,异步更新数据。before checkCharterPrice(cacheDOList,warehouseCode,Code,OrderDO); ...
场景:主流程在历史业务下,越来越繁琐,臃肿,不得不加一堆校验和组装数据,主流程下对多个主表数据操作,记录完本地数据后,调用rpc。
高峰调用
TP95
改造思路:
多线程开启组装数据,对所有非事务操作前置,对大事务拆分,减少重复查询数据,异步更新数据。
before
checkCharterPrice(cacheDOList,warehouseCode,Code,OrderDO);
response.setCode(Code);
OrderDO.setCode(Code);
OrderDO.setWarehouseCode(warehouseCode);
OrderDO.setWarehouseName(warehouseName);
OrderDO.setSignCode(request.getSignCode());
OrderDO.setSuperClass(OrderSuperClassEnum.CLASS_1.value());
List<OrderDetailCacheDO> detailCacheDOS = cacheDOList.stream().filter(DistinctByKeyUtil.distinctByKey(vo -> vo.getShippedOrderCode())).collect(Collectors.toList());
OrderDO.setShippedOrderNum(detailCacheDOS.size());*/
OrderDO.setOrderType(cacheDOList.get(0).getOrderType());
OrderDO.setDriverName(driverSignDO.getDriverName());
OrderDO.setDriverPhone(driverSignDO.getDriverPhone());
OrderDO.setLicensePlate(driverSignDO.getLicensePlate());
OrderDO.setVehicleCategory(driverSignDO.getVehicleCategory());
OrderDO.setVehicleTypeCode(driverSignDO.getVehicleTypeCode());
OrderDO.setVehicleTypeName(driverSignDO.getVehicleTypeName());
OrderDO.setStatus(OrderStatusEnum.STATUS_ENTRUCKED.value());
OrderDO.setSignStatus(SignStatusEnum.SIGN_NO.value());
OrderDO.setStatus(StatusEnum.UNCOMPLETE.value());
OrderDO.setSendDate(driverSignDO.getSendDate());
OrderDO.setCreateBy(request.getUpdateBy());
OrderDO.setCreateTime(new Date());
OrderDO.setSupplierCode(transportVehicleDto.getSupplierCode());
OrderDO.setSupplierName(transportVehicleDto.getSupplierName());
OrderDO.setEntruckSource(request.getEntruckSource());
after
public class BindOrderThreadPool {
public final static ExecutorService BindOrderThreadPool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2 + 1);
}
Future<OrderDO> orderDOFuture = BindOrderThreadPool.BindOrderThreadPool.submit(() -> this.buildOrderBaseInfo(cacheDOList, warehouseCode, finalEntruckingOrderDO));
Future<SignShipped> SignShippedFuture = BindOrderThreadPool.BindOrderThreadPool.submit(() -> this.containerOrderCompleteBind(request, list, productDetailCacheDOList, entruckingOrderDO, entruckingCode, cacheIds, cacheDetailIds, eoddList, signEoddList, warehouseName, transportType));
OrderDO OrderDOByFuture = orderDOFuture.get();
SignShippedDo SignShippedByFuture = SignShippedFuture.get();
executorService.execute(()->{
try {
service.query
} catch (Exception e) {
log.info("任务{}异常",requestParam,e);
}
});
return response.builder().BaseInfo(OrderDOByFuture).SignShippedInfo(SignShippedByFuture ).build;
异步操作改造
before
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
@Override
public void afterCommit() {
if (YesOrNoEnum.YES.value().equals(ConfigDO.getIsSyncCall())) {
mqOrderProducer.isSyncCallOrder(OrderDetailDo);
} else {
handleSync(entruckingOrderDetailDo);
}
}
});
after
final CountDownLatch downLatch = new CountDownLatch(1);
try {
handleSync(entruckingOrderDetailDo);
} catch (Exception e) {
log.info("同步handleSyncy异常",e);
} finally {
downLatch.countDown();
}
原子标识判断是否异常
before
boolean flag = false;
Repository.insertBatch(xxx).var
Repository.insertBatch(xxx).var
Repository.insertBatch(xxx).var
if(flag){
handlerSyncData();
}
after
AtomicBoolean entruckFlag = new AtomicBoolean(false);
if(!entruckFlag.get()){
try {
Repository.insertBatch(xxx).var
Repository.insertBatch(xxx).var
Repository.insertBatch(xxx).var
log.warn("持久化明细表:");
} catch (Exception e) {
e.printStackTrace();
}
}
if(!entruckFlag.get()){
handlerSyncData();
}
对于重复调用数据查询前置
before
for (Response.LogItem logItem : logItemList) { OrderDOentruckingOrder = OrderRepository.getOrder(logItem.getCode(), logItem.getEntruckingCode()); for (PackageConvertResponse packageConvertResponse : packageConvertResponseList) { OrderDOentruckingOrder = OrderRepository.getOrder(logItem.getCode(), logItem.getEntruckingCode()); EntruckingOrderDO entruckingOrderDO1 = entruckingOrderMapper.selectOne(entruckingOrderDO); }}
after
for (Response.LogItem logItem : logItemList) {
OrderDO Order = OrderRepository.getOrder(logItem.getCode(), logItem.getEntruckingCode());
for (PackageConvertResponse packageConvertResponse : packageConvertResponseList) {
Order.getxxx
}
}
完结
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)