I have some simple application with a method for a transaction between 2 objects.
public void transfer(Account source, Account target, double amount) {
// some balance checking
source.setBalance(sourceBalance - amount);
target.setBalance(targetBalance + amount);
}
How to implement transaction i.e. do rollback when some error happens for example in target.setBalance() method for some reasons? I know that in Spring I can use @Transactional annotation when I use jpa repository, but in my case I use objects. These objects stored in in-memory storage - Map<Long, Account>.
question from:
https://stackoverflow.com/questions/65917290/how-to-implement-transaction-when-sharing-data-between-objects-in-java 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…