gpt4 book ai didi

jakarta-ee - UserTransaction.getStatus() 总是返回 '6'

转载 作者:行者123 更新时间:2023-12-03 22:47:33 24 4
gpt4 key购买 nike

UserTransaction.getStatus() 方法总是返回值 '6',即使在执行回滚或提交之后也是如此。无法理解为什么状态没有改变。有人可以指出这里有什么问题吗?
我正在使用 WAS 6.1。

InitialContext context = new InitialContext();
UserTransaction utx = (UserTransaction)context.lookup("java:comp/UserTransaction");
System.out.println("Transaction status = "+utx.getStatus()); //value is 6

utx.begin()
//all work done here

if(all good) {utx.commit()}
else {
utx.rollback();
System.out.println("Transaction status = "+utx.getStatus()); //value is 6
}

最佳答案

安德烈亚斯已经有了答案。我只想为像我这样的人添加一些细节,他们可能认为 STATUS_NO_TRANSACTION 不是已完成交易的直观状态,因为我们在列表中还有一个 STATUS_COMMITTED。

以下是交易可以拥有的所有状态 as listed in EE6 javadoc ;

STATUS_ACTIVE               0
STATUS_COMMITTED 3
STATUS_COMMITTING 8
STATUS_MARKED_ROLLBACK 1
STATUS_NO_TRANSACTION 6
STATUS_PREPARED 2
STATUS_PREPARING 7
STATUS_ROLLEDBACK 4
STATUS_ROLLING_BACK 9
STATUS_UNKNOWN 5

在 javadocs 上,它明确指出我们将在事务完成(提交或回滚)后获得 STATUS_NO_TRANSACTION
static final int STATUS_NO_TRANSACTION
No transaction is currently associated with the target object.
This will occur after a transaction has completed.

那么我们什么时候有 STATUS_ROLLEDBACK 和 STATUS_COMMITTED 呢? Javadocs,类似于这两种状态,表明它们对应于某种有问题的状态,如果没有问题,你会得到一个 STATUS_NO_TRANSACTION;
static final int STATUS_COMMITTED
A transaction is associated with the target object and it has been committed.
It is likely that heuristics exist; otherwise, the transaction
would have been destroyed and NoTransaction returned.

启发式?

这是定义;

A heuristic completion (or heuristic decision) occurs when a resource makes a unilateral decision during the completion stage of a distributed transaction to commit or rollback updates. This can leave distributed data in an indeterminate state. Network failures or resource timeouts are possible causes for heuristic completion.



这意味着,简单地说,您的 XA 事务出了点问题,可能是由于网络、超时等 transient 条件造成的。

很公平。

此外,值得注意的是,WebSphere 如何处理这些启发式完成可以通过 Configuring transaction properties for an application server 中概述的启发式相关属性进行配置。

关于jakarta-ee - UserTransaction.getStatus() 总是返回 '6',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11440060/

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