Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CMT or BMT ?

 
Shanika Dias
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a question with regards to the usage of CMT and BMT in terms of managing transactions in the web application. I have always felt CMT is safer to use and less work so always would choose CMT in my applications.

Are there any drawbacks in using CMT? In what situations one would choose BMT over CMT?

Thanks
Shanika Dias
 
Richard Reese
author
Ranch Hand
Posts: 84
5
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shanika,

You are correct in saying that CMTs are safer and easier to use. They are the preferred way of handling transactions. BMTs are useful for complex transactions and rollback situations. They provide a means to more carefully control the transaction boundaries, that is, when the transaction starts and ends. With CMTs the transactions are bounded by the method. BMTs allow you to specify exactly when and where it ends.

The chief drawback to CMTs in my mind is that the entire method is part of the transaction. If this method is lengthy, then you may be spending more time in the transaction than is needed. This can tie up resources needlessly. Restructuring your code can reduce the time spent in the method.

I would use BMTs where the transaction logic is not handled adequately by CMTs. This can occur when the start and stop of a transaction is not simply at the beginning and end of a method.
 
Shanika Dias
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Richard.

In that case is it possible to have a mix of CMT and BMT in an application, so that for complex, long methods to use BMT and the rest to have CMT?

 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shanika Dias wrote:

In that case is it possible to have a mix of CMT and BMT in an application, so that for complex, long methods to use BMT and the rest to have CMT?



That's possible. Transaction management typically is per component level. i.e. if you applications has multiple components (like EJBs) then each component (i.e. each EJB for example) can have a different transaction management characteristic. One bean can be configured for BMT and the other can use CMT.

 
Shanika Dias
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jaikiran. It's very clear now.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic