public void robotRequestByBrand(MerchantOrderRecordDO merchantOrderRecordDO, CarBrandWmiDO carBrand) {
//匹配机器人,获取有效的供应商【后期可以加入机器人选举策略】
long startTimeEffective = System.currentTimeMillis();
List<RobotEffectiveInfo> effectiveRobotList = maintenanceManager.getEffectiveRobot(carBrand, merchantOrderRecordDO);
log.info("&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*选举的机器人的数量:" + effectiveRobotList.size());
long endTimeEffective = System.currentTimeMillis();
log.info("&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*选举机器人运行时间:" + (endTimeEffective - startTimeEffective) + "ms");
alternateBrandUtilContext.saveCurrOrderBrand(merchantOrderRecordDO,carBrand);
//异步请求机器人
CompletableFuture.runAsync(() -> {//代码一直没有执行
try {
long startTime = System.currentTimeMillis();
log.info("第三步:异步请求机器人~~," + merchantOrderRecordDO.getVin());
maintenanceManager.syncRequestRobot(effectiveRobotList, merchantOrderRecordDO);
long endTime = System.currentTimeMillis();
log.info("&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*整个异步流程运行时间:" + (endTime - startTime) + "ms");
} catch (Exception e) {
log.info("异步请求机器人发生异常########################,vin: {}", merchantOrderRecordDO.getVin());
e.printStackTrace();
}
});
log.info("第四步:异步请求机器人完成~~," + merchantOrderRecordDO.getVin());
}
你这里主线程执行完毕,异步线程未必执行完毕。加个join()
public void robotRequestByBrand(MerchantOrderRecordDO merchantOrderRecordDO, CarBrandWmiDO carBrand) {
//匹配机器人,获取有效的供应商【后期可以加入机器人选举策略】
long startTimeEffective = System.currentTimeMillis();
List<RobotEffectiveInfo> effectiveRobotList = maintenanceManager.getEffectiveRobot(carBrand, merchantOrderRecordDO);
log.info("&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*选举的机器人的数量:" + effectiveRobotList.size());
long endTimeEffective = System.currentTimeMillis();
log.info("&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*选举机器人运行时间:" + (endTimeEffective - startTimeEffective) + "ms");
alternateBrandUtilContext.saveCurrOrderBrand(merchantOrderRecordDO,carBrand);
//异步请求机器人
CompletableFuture.runAsync(() -> {//代码一直没有执行
try {
long startTime = System.currentTimeMillis();
log.info("第三步:异步请求机器人~~," + merchantOrderRecordDO.getVin());
maintenanceManager.syncRequestRobot(effectiveRobotList, merchantOrderRecordDO);
long endTime = System.currentTimeMillis();
log.info("&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*整个异步流程运行时间:" + (endTime - startTime) + "ms");
} catch (Exception e) {
log.info("异步请求机器人发生异常########################,vin: {}", merchantOrderRecordDO.getVin());
e.printStackTrace();
}
}).join(); //等待一下
log.info("第四步:异步请求机器人完成~~," + merchantOrderRecordDO.getVin());
}