gpt4 book ai didi

java - JtaTransactionManager 和 ChainedTransactionManager 之间的区别?

转载 作者:IT老高 更新时间:2023-10-28 13:44:18 25 4
gpt4 key购买 nike

我需要管理我的应用程序中的多个资源,例如 jmsdatabase

在查看可以管理多个资源的事务管理器时,我遇到了 2 个事务管理器 JtaTransactionManagerChainedTransactionManager,它们几乎声称他们可以管理多个资源。

谁能解释它们的主要区别是什么?我什么时候应该使用哪一个?

最佳答案

如文档所述: ChainedTransactionManger doc :

PlatformTransactionManager implementation that orchestrates transaction creation, commits and rollbacks to a list of delegates. Using this implementation assumes that errors causing a transaction rollback will usually happen before the transaction completion or during the commit of the most inner PlatformTransactionManager. The configured instances will start transactions in the order given and commit/rollback in reverse order, which means the PlatformTransactionManager most likely to break the transaction should be the last in the list configured. A PlatformTransactionManager throwing an exception during commit will automatically cause the remaining transaction managers to roll back instead of committing.

这意味着您可以通过向其传递多个事务管理器来创建 ChainedTransactionManager。如果一个事务管理器发生异常,则会按指定的相反顺序为所有事务管理器生成回滚

JtaTransactionManager doc :

PlatformTransactionManager implementation for JTA, delegating to a backend JTA provider. This is typically used to delegate to a Java EE server's transaction coordinator, but may also be configured with a local JTA provider which is embedded within the application. This transaction manager is appropriate for handling distributed transactions, i.e. transactions that span multiple resources, and for controlling transactions on application server resources (e.g. JDBC DataSources available in JNDI) in general. For a single JDBC DataSource, DataSourceTransactionManager is perfectly sufficient, and for accessing a single resource with Hibernate (including transactional cache), HibernateTransactionManager is appropriate, for example.

您可以使用此事务管理器来管理多个资源的分布式事务

关于java - JtaTransactionManager 和 ChainedTransactionManager 之间的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33202841/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com