我使用 Java 1.6、Tomcat 和带有 JDBC 和持久性框架的 servlet。我知道(并使用)数据库级事务,但我想知道是否有用于应用程序级回滚和提交的框架?
我确信它有一个特定的名称,但是可以让我以比当前实现它更标准的方式编码和测试以下内容:
- get user info
- charge credit card
- create mailing labels
- write db
if any fail, then rollback and:
- cancel credit card charge
- invalidate mailing label
- rollback DB
else
- commit. (i.e. do it all with threads)
这有意义吗?
到目前为止,我正在处理所有逻辑和错误检查...想知道是否有一个很好的框架可以提供帮助,因为这变得越来越复杂。
最佳答案
听起来你基本上在想 software transactional memory 。我不会做比维基百科摘要更好的事情:
In computer science, software transactional memory (STM) is a concurrency control mechanism analogous to database transactions for controlling access to shared memory in concurrent computing. It is an alternative to lock-based synchronization. A transaction in this context is a piece of code that executes a series of reads and writes to shared memory. These reads and writes logically occur at a single instant in time; intermediate states are not visible to other (successful) transactions.
这是一个非常有趣的想法,但我还不知道它是否真正“大范围”流行起来。我认为这主要限于研究。也就是说,做了一些搜索发现 Multiverse, a seemingly halfway interesting implementation我以前没听说过,但有教程和网站...
关于java - 是否有用于应用程序级(而非数据库)事务(例如回滚)的框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11422173/