Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
138 views
in Technique[技术] by (71.8m points)

How to implement transaction when sharing data between objects in java

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...