BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Transaction Strategies Based on Java Transaction Models

Transaction Strategies Based on Java Transaction Models

Leia em Português

This item in japanese

Bookmarks

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:

  • "The Client Orchestration transaction strategy is used when multiple server-based or model-based calls from the client layer fulfill a single unit of work.
  • The API Layer transaction strategy is used when you have coarse-grained methods that act as primary entry points to back-end functionality. (Call them services if you would like.)
  • The High Concurrency transaction strategy, a variation of the API Layer transaction strategy, is used for applications that cannot support long-running transactions from the API layer (usually because of performance or scalability needs).
  • The High-Speed Processing transaction strategy is perhaps the most extreme of the transaction strategies. You use it when you need to get the absolute fastest possible processing time (and hence throughput) from your application and still maintain some degree of transactional atomicity in your processing.

Mark Richards is the author of an InfoQ mini-book Java Transaction Design Strategies that provides additional background information for this important topic.

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

  • Transaction Strategies

    by Dimitre Tonev,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    What are your thoughts on transparent transaction management? Meaning that the container automatically determines the need of transaction and manages the life cycle of it (commit/rollback) without any declarative definitions. It is certainly possible within a web container, which knows the start and end of the user request.

  • More info on the strategies?

    by Guy Pardon,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Hi,

    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

    Best

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT