1 Reply Latest reply on Jun 3, 2003 5:11 AM by marklittle

    Multi-thread in a Transaction

    henrichen

      Hi,

      I use a third party library in my EJB bean. However, the library uses a multi-thread technique to implement its function (somehow use wait() and notify() as longjmp and pass flow between parent thread and new created child thread).

      The new created thread apperently has no transaction associated with it (TransactionManager.getTransaction() return null) and things is finally gone wrong. Is there a way to "propagate" the transaction information to the new created thread?

      I checked the source code of jboss 3.06, it seems the TxManager.java is the jboss's implementation of TransactionManager which uses a ThreadLocal to hold the TransactionInfo. Is it possible to use InheritableThreadLocal instead? That way, the new thread would naturally hold the ThreadLocal value of the parent thread and TransactionManager.getTransaction() would get the same transaction back in the new Thread.

      Would some gurus familiar with JTA please give comments(answers, hints) on this kind of issue? Thank you very much.

      Henri Chen
      henrichen@potix.com

        • 1. Re: Multi-thread in a Transaction
          marklittle

          The JTA allows implementations that don't support multiple threads in the same transaction or those that do. There are a lot of issues with the latter approach, such as checked transaction semantics, that simply don't exist in a uni-thread model.

          The only way in the JTA itself to *try* to associate multiple threads with the same transaction would be to call getTransaction on the thread that currently has the transaction association, and then try a resume with the returned Transaction in the scope of the thread that doesn't have the association. I'm pretty sure JBoss TM supports this, but there are some implementations that don't (e.g., JOTM). So beware :-)

          Mark.