我在JPA中遇到线程事务的问题 . 所以,我有一个从一些线程并行调用的方法 . 该方法正在执行2个表的删除 . 第一个删除工作正常,因为每个线程都从记录中删除一个部分 . 所有线程的第二次删除都是相同的 . 我的意思是只有一个线程应该从第二个表中删除,其他线程将检查没有任何记录并跳过删除 .
我的代码:
@Override
@Transactional(isolation = Isolation.SERIALIZABLE)
public void deleteAll(List<PushedImsi> pushedImsis, Date currentDate, String deviceIp) {
pushedImsiRepository.deleteAllByExpireDateBeforeAndDeviceIp(currentDate, deviceIp);
if (imsiService.countAllByExpireDateBefore(currentDate) != 0) {
List<Imsi> expiredImsis = imsiService.findByExpireDateBefore(currentDate);
imsiService.deleteAllByExpireDateBefore(currentDate, expiredImsis);
}
}
错误: java.util.concurrent.ExecutionException: org.springframework.dao.CannotAcquireLockException: could not execute batch; SQL [delete from imsi where objectKey=?]
我也尝试同步该方法,但我收到了批量更新0错误的东西 .
好吗,拜托?