5 Replies Latest reply on Apr 28, 2014 3:33 AM by anderruiz

    WS-AT Single UserTransaction object

    anderruiz

      I'm implementing an application based on webservices described here

       

      XTS + JTA + MyBatis-Spring

       

      I managed to create UserTransactions and to solve the problem with WS calls that don't have a transaction associated with it, but while solving some strange WrongStateException I was getting I discovered that everytime I call

       

      UserTransaction t = UserTransactionFactory.userTransaction();
      

       

      The transaction object that I get is the same instance (hashCode is the same) between different calls for different real transactions (their uuid is different).

       

      My question is, is XTS module prepared for parallel transaction handling? probably yes, so is this possible even though we have a single instance for UserTransaction or is there any configuration change that I need?

        • 1. Re: WS-AT Single UserTransaction object
          gytis

          Hello Ander,

           

          yes XTS is thread safe. Even thought we do have a single instance of the UserTransaction class, it operates using the information available on the current thread (we use java.lang.ThreadLocal there).

           

          Gytis

          • 2. Re: Re: WS-AT Single UserTransaction object
            anderruiz

            I'm a bit surprised because I don't understand how can UserTransaction be thread safe and have some errors I was(am) getting. I understand that:

             

            UserTransaction t = UserTransactionFactory.userTransaction(); 
            

             

            Fills UserTransaction object with the values required for the current thread but what happens if at the same moment another Thread invokes the same instruction?, what I think is that the first Thread will see the modifications of the second. Or am I missing something?

             

            This is based on my observation, originally I was creating a UserTransaction object in the start of a task and using the same object to commit or rollback in the end. If in the meantime I was receiving a WS call I was creating a "new" UserTransaction and the original task was commiting the transaction for the WS instead of its own. I minimized the errors by calling UserTransaction.userTransaction before the commit but I could still have race conditions

            • 3. Re: Re: WS-AT Single UserTransaction object
              gytis

              To answer your question "what happens if at the same moment another Thread invokes the same instruction?":

                   UserTransaction object will always be the same for every thread. However, transaction information associated with the thread is different, based on the information received with WS request. Transaction context associated with the thread is handled by the context manager (narayana/XTS/WSTX/classes/com/arjuna/mwlabs/wst/at/remote/ContextManager.java at 4.17.13.Final · jbosstm/narayana · GitH…).

               

              Second part of the message is not very clear to me. Could you provide the stack trace with an error message. And also clarify the scenario which is failing?

              • 4. Re: WS-AT Single UserTransaction object
                paul.robinson

                Ander,

                 

                I agree with Gytis, this does sound strange. Can you provide a simple reproducer so we can see it happening? This will make it a lot easier for us to fix or identify what you are doing wrong.

                 

                Paul

                • 5. Re: WS-AT Single UserTransaction object
                  anderruiz

                  It may have been my own mistake, I'm testing it and will provide more information as soon as I have one conclusion