所以在我正在研究的项目中,我有一个由TimerService触发的Seam组件,并执行一个方法来更新一些数据。此方法通常运行几秒钟,但有时可能需要几分钟。
我的问题是,如果此方法花费的时间太长,Arjuna TransactionReaper会启动并杀死组件。默认超时设置为5分钟,这对所有其他组件都是足够的,我不想更改它。
以下是我的代码中的一些简单的部分:
@Name("myComp")
@Stateful(mappedName = "myComp")
@Scope(APPLICATION)
@TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionTimeout(timeout = 3600) //own implementation, used by Transaction class, see below
public class MyComp implements MyCompLocal
{
@Override
public void update() {/*...*/}
}
StackOverflow上的某个地方(我找不到包含这个的确切问题,否则我会链接到它)我找到了一个解决方案,听起来确实不错:覆盖Seams Transaction类并在UserTransaction上设置超时,所以我这样做了:
@Name("org.jboss.seam.transaction.transaction")
@Scope(ScopeType.EVENT)
@Install(precedence=APPLICATION)
@BypassInterceptors
public class Transaction extends org.jboss.seam.transaction.Transaction
{
@Override
protected UserTransaction getUserTransaction() throws NamingException
{
UserTransaction ut = super.getUserTransaction();
ut.setTransactionTimeout(getTimeout()); //getTimeout() uses the value set by the TransactionTimeout annotation, done by analyzing the stacktrace and reflection
return ut;
}
}
这实际上似乎在调用代码并在UserTransaction上设置超时的意义上起作用。然而问题是,Arjuna似乎并不关心这一点,我仍然得到:
WARN [arjuna] ARJUNA-12117 TransactionReaper::check timeout for TX 0:ffffc0a88364:126a:53eb7613:8a in state RUN
WARN [arjuna] ARJUNA-12095 Abort of action id 0:ffffc0a88364:126a:53eb7613:8a invoked while multiple threads active within it.
WARN [arjuna] ARJUNA-12108 CheckedAction::check - atomic action 0:ffffc0a88364:126a:53eb7613:8a aborting with 1 threads active!
WARN [arjuna] ARJUNA-12121 TransactionReaper::doCancellations worker Thread[Transaction Reaper Worker 0,5,jboss] successfully canceled TX 0:ffffc0a88364:126a:53eb7613:8a
WARN [arjuna] ARJUNA-12117 TransactionReaper::check timeout for TX 0:ffffc0a88364:126a:53eb7613:8b in state RUN
WARN [arjuna] ARJUNA-12095 Abort of action id 0:ffffc0a88364:126a:53eb7613:8b invoked while multiple threads active within it.
WARN [arjuna] ARJUNA-12108 CheckedAction::check - atomic action 0:ffffc0a88364:126a:53eb7613:8b aborting with 1 threads active!
WARN [arjuna] ARJUNA-12121 TransactionReaper::doCancellations worker Thread[Transaction Reaper Worker 0,5,jboss] successfully canceled TX 0:ffffc0a88364:126a:53eb7613:8b
在调用方法后五分钟后。 因此,似乎Arjuna根本不关心UserTransaction的超时设置。我可能会考虑哪些提示来解决这个问题?
Btw。:JBossAS 6.1.0.Final,jdk_1.7.0_13,JBossTS 4.14.0.Final,Seam 2.2.2.Final
答案 0 :(得分:0)
您不能为每个资源管理器设置超时(如果您要这样做),但是可以为每个事务设置超时(在调用UserTransaction.begin之前)