aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes CMT or BMT ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "CMT or BMT ?" Watch "CMT or BMT ?" New topic
Author

CMT or BMT ?

Shanika Dias
Greenhorn

Joined: Jul 31, 2011
Posts: 5
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

Joined: Jul 13, 2011
Posts: 84
    
    5

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.


Richard Reese
Java 8 New Features: A Practical Heads-Up Guide
Shanika Dias
Greenhorn

Joined: Jul 31, 2011
Posts: 5
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

Joined: Jul 20, 2005
Posts: 10091
    
164

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.


[My Blog] [JavaRanch Journal]
Shanika Dias
Greenhorn

Joined: Jul 31, 2011
Posts: 5
Thanks Jaikiran. It's very clear now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: CMT or BMT ?