Итак,
- является ли метод sendConfirmation внутри транзакции?
- делает ли Контекст другого threadlocal @Async повлиял на контекст исходного threadlocal и получил sendConfirmation из транзакции?
- удаление @Async меняет процесс или нет?
@AllArgsConstructor
public class OrderServiceImpl implements OrderService {
private final OrderRepository orderRepository;
private final NotificationService notificationService;
@Override
@Transactional
public void processOrder(Order order) {
order.setStatus(OrderStatus.PROCESSING);
orderRepository.save(order);
notificationService.sendConfirmation(order); // @Async method
order.setStatus(OrderStatus.CONFIRMED);
orderRepository.save(order);
}
}
@Service
public class NotificationServiceImpl implements NotificationService {
@Async
@Override
public void sendConfirmation(Order order) {
// Send email...
log.info("Sending confirmation for order: {}", order.getId());
}
}
Подробнее здесь: https://stackoverflow.com/questions/798 ... ransaction
Мобильная версия