5 Replies Latest reply on Jul 8, 2013 5:21 AM by Michael Musgrove

    De associating thread from a transaction

    Aby V Newbie

      Hi,

      I am using Jboss Jta to manage a standalone application. The different process can be executed parellely using Java threads. Since, i need to demarcate the whole process within a single transaction boundary, i took the following approach.

      I started a transaction from the originator( transactionmanager.begin)

      A process P1  is delegated to a new thread T1 there I initiated a new transactionmanager instance T1

      ( txnmanager1.begin)

      Similarly another process P2 is delegated to  thread T2 and began a transaction as shown above.

      Once the child process( P1 and P2) completes, the respective transactionmanager instances  are suspended. The suspended transactions are returned back( using call back mechanism) to parent thread.

      The parent transaction suspends its current transaction and resumes the child transaction instance.  The snippet for parent transaction controlling the child threads are  as shown below:

           Transaction t = txnManager.suspend();//Parent transaction

            txnManager.resume( t1)

            txnManager.commit();

            txnManager.resume( t2)

            txnManager.commit( t2);

            txnManager.resume( t);

            txnManager.commit();


      The concept above works fine for  sub transactions with  a 1 to 1 mapping between the process and thread.( i.e each process is associated to a dedicated thread). The problem I am currently dealing with is ...

      Would it be possible to control multiple threads using a single transaction context( one transaction manager instance) such that if the process in any one of the thread fails( rolls back), the entire transaction rolls back. whereas the begin cycle of the transaction manager will be invoked from the main thread before spawning the child threads and commit willl be called only after joining the child threads.?

        • 1. Re: De associating thread from a transaction
          Mark Little Master

          Narayana supports multiple threads being active in the same transaction at the same time. If one of them successfully marks the transaction as rollback-only, then the transaction must rollback. There's also the concept of a CheckedAction (see the documentation), which allows you to do some interesting things in a thread(s) once the transaction terminates.

          1 of 1 people found this helpful
          • 2. Re: De associating thread from a transaction
            Aby V Newbie

            Thank You once again Mark, I am using the jboss jta 4.17 version  as a library for my application( using the maven pom uploaded in the maven repository). When I tested for multiple threads, it was raising an illegalstateException,since a transaction can be associated to  only a single thread at a time. Do I need to import the entire maven module of Jboss jts 5.0.0  for the multi threading feature ?

            Do I need to use OTS API''s( in place of javax.jta.TransactionManager) to achieve this ?

            • 3. Re: De associating thread from a transaction
              Michael Musgrove Master

              Are you using the JTS version of the product and did you set the property com.arjuna.ats.jts.checkedTransactions to true (you set it in the properties file or programatically by calling jtsPropertyManager.getJTSEnvironmentBean().setCheckedTransactions(true)).

               

              I think this is a JTS only supported feature.

              • 4. Re: De associating thread from a transaction
                Aby V Newbie

                ThanK You Michael I was expecting this feature to be part of JTA implementation,

                I am using the jboss jta library, i doubt this includes the jts feature. Currently I am loading the transaction manager from the JTAPropertyManager. I am excited about the JTS feature, for that I would like to know, how I would switch from jboss jta to jts implementation.?

                • 5. Re: De associating thread from a transaction
                  Michael Musgrove Master

                  This is covered in http://docs.jboss.org/jbosstm/5.0.0.M3/guides/narayana-jts-administration_guide/index.html#d0e633 but basically you need to set two properties to switch the library into JTS mode. Progamatically you would need to call the following before using the TM:

                   

                      JTAEnvironmentBean jtaEnvironmentBean = BeanPopulator.getDefaultInstance(JTAEnvironmentBean.class);

                   

                      jtaEnvironmentBean.setTransactionManagerClassName(com.arjuna.ats.internal.jta.transaction.jts.TransactionManagerImple.class.getName());  

                      jtaEnvironmentBean.setUserTransactionClassName(com.arjuna.ats.internal.jta.transaction.jts.UserTransactionImple.class.getName());

                   

                  and similarly if you want to do it via the properites file.

                  1 of 1 people found this helpful