编写测试代码:
@Test
public void callBack() throws InterruptedException {
ExecutorService executorService = Executors.newFixedThreadPool(100);
for (int i = 0; i < 100; i++) {
executorService.execute(new Runnable() {
@Override
public void run() {
try {
payBack();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
public void payBack() {
String tradeNo = "202259607180675101";
//log.info("--------"+tradeNo+"--------");
//通过tradeNo查询订单状态。交易单号
ProductOrderDO productOrderDO = productOrderService.queryProductOrderState(tradeNo);
if(productOrderDO == null) {
log.error("--------fail--------------------"); ;
}
log.info("--------"+tradeNo+"--------");
String orderState = productOrderDO.getState();
//sleep(1000l);
log.info("--------"+orderState+"--------");
}
发现SQL根本没有执行,出现报错
[“SqlSession[xxx] was not registered for synchronization because synchronization is not active
原因是Sqlsession未注册同步,同步注册未激活,JDBC connection不能被Spring所托管,,,callBack方法加事务注解@Transactional就可以了
网友评论