我的问题是:事务如何在这样的代码中表现?
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void test(List<Long> ids) {
List<CompletableFuture> list = ids.stream().parallel()
.map(id -> build(id))
.collect(Collectors.toList());
// other logic
}
private CompletableFuture build(Long id) {
return CompletableFuture.supplyAsync(() -> Calculation.builder().id(id).build(), someExecutor)
.thenApply(calculationRepository::save);
}
我认为它会中断,因为a)私有方法b)其他线程
是否有保存交易的方法? (代码示例是合成的,但是概念应该清楚)