Transaction Strategies Based on Java Transaction Models
The concept of a transaction is essential to assure data integrity and consistency. A complete understanding of transactions requires familiarity with basics, models, and strategies. Mark Richards notes " It's a common mistake to confuse transaction models with transaction strategies." This article covers " the three transaction models supported by the Java™ platform and introduces four primary transaction strategies that use those models. Using examples from the Spring Framework and the Enterprise JavaBeans (EJB) 3.0 specification, Mark explains how the transaction models work and how they can form the basis for developing transaction strategies ranging from basic transaction processing to high-speed transaction-processing systems."
The Java platform supports three transaction models:
- Local Transaction model - transactions are managed by the DB resource and not in the application container or framework. The developer manages connections rather than transactions.
- Programmatic Transaction model - the programmer obtains a transaction from a transaction manager but then must write their own code for starting, committing and, given an exception, rolling back the transaction. And,
- Declarative Transaction model - the most common model, also known as Container Managed Transaction. In this model the container actively manages the transaction, the developer defines (declares) the behavior and parameters of the transaction.
but this support is limited to a description of transaction basics and expected behaviors; description of the implementation, and rules and syntax for use. A transaction strategy is required to answer questions like: 'when should I use the REQUIRED vs. MANDATORY attributes, specific directives, one model vs. another, or how to optimize for a particular situation?
The benefits and the pitfalls of the transaction models are discussed by Mark in a preceding article.
Strategies for using specific models and using a given model in an appropriate manner are introduced in this article. The four strategies presented are:
Mark Richards is the author of an InfoQ mini-book Java Transaction Design Strategies that provides additional background information for this important topic.
More info on the strategies?
I don't know if I missed something, but I didn't find a lot on the actual strategies except the summary at the end. Is there any detailed explanation?
Also, you can have something in between local transactions and distributed transactions: www.atomikos.com/Publications/TryCancelConfirm
Yoni Goldberg Oct 30, 2014
Dmytro Svarytsevych Oct 30, 2014