O'Reilly logo

Java Enterprise in a Nutshell, Third Edition by William Crawford, Jim Farley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Transaction Best Practices

We recommend the following transaction management best practices :

  • Use declarative transaction management rather than programmatic transactions whenever possible.

  • When using declarative transactions with EJBs, consider using Required as the first choice for a transaction attribute.

  • When using distributed transactions, use XA-enabled resources and XA-enabled drivers whenever possible. Be aware of the limitations of emulating XA for a non-XA resource.

  • Avoid mixing direct transaction management using JTA with implicit transaction management done through a resource-specific API such as JDBC or JMS since this complicates the transaction management picture.

  • Consider leveraging the session façade design pattern for creating coarse-grained transactions.

  • Minimize the use of client-managed transactions wherever possible. The session façade can be useful here.

  • Carefully evaluate the need and implementation of an optimistic concurrency strategy.

Transactions help you to manage very complex, and even unpredictable, system behavior when dealing with shared networked resources. But as this chapter has demonstrated, you must learn to leverage transactions in the most efficient and straightforward manner possible. To that end, having a solid understanding of transaction terms and concepts such as ACID properties, local versus distributed transactions, the flat transaction model, two-phase commit, isolation problems and levels, and optimistic concurrency is essential.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required