Programming BMT - UserTransaction

ε祈祈猫儿з 提交于 2019-12-12 03:06:03

问题


Is the complete programming of BMT based on UserTransaction interface? In other words, if I want to use BMT, is there any scenario when I would require more services than those provided by the UserTransaction interface.

Why this question? If I use a different implementation of the transaction manager (such as Bitronix TM or Atomikos) and not the default provided by the container, is it just enough to inject the new TM into UserTransaction object?

-Thanks


回答1:


This is really limited to what the app server itself will allow; i.e. if it explicitly supports replacing the transaction manager.

The real art to transaction management is the container registering transactional resources (DataSource connections, JMS Sessions, JPA EntityManagers, etc) with the TransactionManager via wrapping them with Synchronization objects and registering them with the current transaction via either the Transaction or the TransactionSynchronizationRegistry

The container implements the Synchronization objects, the TransactionManager implements the Transaction and TransactionSynchronizationRegistry objects. The coordination between the two is what gives you actual management when a transaction is running.

BMT and CMT are just alternate ways to tell the container to start/stop transactions. In some regards the term "Bean-Managed" is false as the UserTransaction in every compliant app server will be implemented by the container and thus it is still the container doing the work. As well "Container-Managed" is slightly misleading as it is still the bean developer deciding when transactions are started/stopped, it's just done declaratively vs programmatically. The most accurate description of these features would be Programmatically-Managed Transactions and Declaratively-Managed Transactions. In all cases it is still the bean talking with the container and the container and transaction manager doing all the work.

All that said it may still be possible for you to change the transaction manager, OpenEJB and TomEE support it, however it will not work in the way you are attempting. Check with your vender to see if this is possible.




回答2:


Maybe not entirely answering your question, but if using BMT you are also allowed to use resource local transaction managers. In that case you would not use the (injected) UserTransaction interface.

Do note that this is only legal if no transaction is in progress that is started via the said UserTransaction interface.



来源:https://stackoverflow.com/questions/8700628/programming-bmt-usertransaction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!