Springboot在Service中加一一个线程无法接交事务

final String stufIds=Json.findIds(details, "pdStufId");
//stuffService.countByIds(stufIds);
new Thread(new Runnable() {
@Transactional
public void run() {
try {
stuffService.countByIds(stufIds);
Thread.sleep(10);
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}

这是一个代码片断,原来的
stuffService.countByIds(stufIds);
我注释掉了,这个是结算的算法,我不想在Service等,太慢了
所以想开一个线程,异步去执行,
之前注意现在才发现,他是执行了,但是没有提交 事务,

我用的是Hibernate,会的帮忙指点一下

你为何会在run上加事务注解?Spring的注解都是对Context中注册的bean才生效的,你的匿名抽象类不属于Context管理的bean。正常操作都是在定义countByIds方法时加上吧

https://blog.csdn.net/lanyanhua/article/details/103824504