交易是交替超时

ray*_*man 11 java transactions java-ee jboss5.x ejb-3.0

我使用的是jboss 5.1.x,EJB3.0

我有MDB,它监听JMS队列.当MDB收到消息时,它会通过TCP向某个调制解调器发送一个msg.有时,当服务器等待答案时,调制解调器没有响应:

      byte[] byteData = receive(is);
Run Code Online (Sandbox Code Playgroud)

因为我无法在InputStream上设置超时.

所以感谢EJB容器事务超时(默认存在)回滚操作然后再次执行重试.

这个机制默认对我来说很好,问题是:

有时事务永远不会超时,并且很长一段时间后我在控制台中得到以下消息:

  15:18:22,578 WARN  [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TransactionReaper_18] - TransactionReaper::check timeout    for TX a6b2232:5f8:4d3591c6:76 in state  RUN
  15:18:22,578 WARN  [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.BasicAction_58] - Abort of action id a6b2232:5f8:4d3591c6:76 invoked while multiple threads active within it.
  15:18:22,578 WARN  [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.CheckedAction_2] - CheckedAction::check - atomic action a6b2232:5f8:4d3591c6:76 aborting with 1 threads active!
   15:18:22,578 WARN  [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TransactionReaper_7] - TransactionReaper::doCancellations worker Thread[Thread-10,5,jboss] successfully canceled TX a6b2232:5f8:4d3591c6:76
Run Code Online (Sandbox Code Playgroud)

知道什么是错的吗?为什么有时它会起作用,有时它不起作用?

谢谢,

射线.

Nay*_*kar 11

JBossAS使用Arjuna的事务管理器.在EJB3中,拦截器链将开始展开并最终命中事务管理器拦截器,其作用是中止事务.

  • 对于MDB,你可以用它来表示 @ActivationConfigProperty(propertyName="transactionTimeout" value="1500")

  • 对于其他bean,您可以@TransactionTimeout(1500)在类级别或方法级别拥有.

当事务管理器检测到事务已超时,然后从异步线程(不同于方法中运行的线程)中止它时,它从不向当前运行的线程发送中断.

因此导致:在多个线程处于活动状态时调用 ... 中止1个线程处于活动状态!

编辑:

//---

ThreadGroup root = Thread.currentThread().getThreadGroup().getParent();

while (root.getParent() != null)
  root = root.getParent();

findAllThread(root,0);

//---

public static findAllThread(ThreadGroup threadGroup, int level){

    int actCount = threadGroup.activeCount();
    Thread[] threads = new Thread[actCount*2];
    actCount = threadGroup.enumerate(threads, false);


    for (int i=0; i<actCount; i++) {
        Thread thread = threads[i];
        thread.interrupt();
    }

    int groupCount = threadGroup.activeGroupCount();
    ThreadGroup[] groups = new ThreadGroup[numGroups*2];
    groupCount = threadGroup.enumerate(groups, false);

    for (int i=0; i<groupCount; i++) 
        findAllThread(groups[i], level+1);

//---
Run Code Online (Sandbox Code Playgroud)

它将列出其他活动线程,如参考处理程序,终结器,信号调度程序等.