8 Replies Latest reply on Apr 13, 2007 12:19 PM by marklittle

    Transaction not active & threads

    bentins

      Sometimes my application gets into a situation where a UserTransaction goes into a state of Transaction Not Active. I know how it gets there and why. Fixed it on the next version of the application, however I noticed something strange which I'd like someone to explain to me.

      My application is a web application running on 4.0.3SP1. The users are web users. When a user invokes an action on the server side that goes into the situation I described with the transaction, from that point on whatever he does (even if he goes elsewhere in the application) he always gets the same "dead" transaction. Other users continue working as usual.

      What I don't understand is since web clients are stateless, how come this session always gets the same dead user Transaction and not another clean one? Isn't there a pool of userTrasnaction for users? or is there only one which in turn is given to each user?

        • 1. Re: Transaction not active & threads
          marklittle

          Which transaction service implementation?

          • 2. Re: Transaction not active & threads
            bentins

            it seems that I use the default transaction service which is "ClientUserTransactionService" with "org.jboss.tm.usertx.interfaces.UserTransactionSessionFactory"

            here is the config


            <server>
             <!-- ==================================================================== -->
             <!-- Transactions -->
             <!-- ==================================================================== -->
             <!-- The configurable Xid factory. For use with Oracle, set pad to true -->
             <mbean code="org.jboss.tm.XidFactory"
             name="jboss:service=XidFactory">
             <attribute name="Pad">true</attribute>
             </mbean>
            
             <!--
             | The fast in-memory transaction manager.
             -->
             <mbean code="org.jboss.tm.TransactionManagerService"
             name="jboss:service=TransactionManager"
             xmbean-dd="resource:xmdesc/TransactionManagerService-xmbean.xml">
             <attribute name="TransactionTimeout">300</attribute>
             <!-- set to false to disable transaction demarcation over IIOP -->
             <attribute name="GlobalIdsEnabled">true</attribute>
             <depends optional-attribute-name="XidFactory">jboss:service=XidFactory</depends>
             <depends>jboss:service=Naming</depends>
             </mbean>
             <!--
             | UserTransaction support.
             -->
             <mbean code="org.jboss.tm.usertx.server.ClientUserTransactionService"
             name="jboss:service=ClientUserTransaction"
             xmbean-dd="resource:xmdesc/ClientUserTransaction-xmbean.xml">
             <depends>
             <mbean code="org.jboss.invocation.jrmp.server.JRMPProxyFactory"
             name="jboss:service=proxyFactory,target=ClientUserTransactionFactory">
             <attribute name="InvokerName">jboss:service=invoker,type=jrmp</attribute>
             <attribute name="TargetName">jboss:service=ClientUserTransaction</attribute>
             <attribute name="JndiName">UserTransactionSessionFactory</attribute>
             <attribute name="ExportedInterface">org.jboss.tm.usertx.interfaces.UserTransactionSessionFactory</attribute>
             <attribute name="ClientInterceptors">
             <interceptors>
             <interceptor>org.jboss.proxy.ClientMethodInterceptor</interceptor>
             <interceptor>org.jboss.invocation.InvokerInterceptor</interceptor>
             </interceptors>
             </attribute>
             <depends>jboss:service=invoker,type=jrmp</depends>
             </mbean>
             </depends>
             <depends optional-attribute-name="TxProxyName">
             <mbean code="org.jboss.invocation.jrmp.server.JRMPProxyFactory"
             name="jboss:service=proxyFactory,target=ClientUserTransaction">
             <attribute name="InvokerName">jboss:service=invoker,type=jrmp</attribute>
             <attribute name="TargetName">jboss:service=ClientUserTransaction</attribute>
             <attribute name="JndiName"></attribute>
             <attribute name="ExportedInterface">org.jboss.tm.usertx.interfaces.UserTransactionSession</attribute>
             <attribute name="ClientInterceptors">
             <interceptors>
             <interceptor>org.jboss.proxy.ClientMethodInterceptor</interceptor>
             <interceptor>org.jboss.invocation.InvokerInterceptor</interceptor>
             </interceptors>
             </attribute>
             <depends>jboss:service=invoker,type=jrmp</depends>
             </mbean>
             </depends>
             </mbean>
            </server>
            
            


            • 3. Re: Transaction not active & threads
              marklittle

               

              "bentins" wrote:
              Sometimes my application gets into a situation where a UserTransaction goes into a state of Transaction Not Active. I know how it gets there and why. Fixed it on the next version of the application, however I noticed something strange which I'd like someone to explain to me.

              My application is a web application running on 4.0.3SP1. The users are web users. When a user invokes an action on the server side that goes into the situation I described with the transaction, from that point on whatever he does (even if he goes elsewhere in the application) he always gets the same "dead" transaction. Other users continue working as usual.

              What I don't understand is since web clients are stateless, how come this session always gets the same dead user Transaction and not another clean one? Isn't there a pool of userTrasnaction for users? or is there only one which in turn is given to each user?


              I suspect that the transaction is being terminated via the Transaction interface and not via UserTransaction. Only the latter changes the thread-to-transaction association, so the dead transaction will remain associated with that thread.

              • 4. Re: Transaction not active & threads
                bentins

                Well, I'm sure I'm using the correct interace for termination because I terminate on the userTransaction object manually. However, the problem is that my bug was that the transaction does not get terminated because of mishendeling of a runtime exception. (this is what i fixed...). So if I read between the lines of what you wrote I see that there is a match up between a thread and a transaction (which makes sense) and somehow a matchup between a user's session and a thread???

                • 5. Re: Transaction not active & threads
                  marklittle

                  When a thread begins a transaction via UserTransaction (or TransactionManager) it will be associated with that thread. If that thread doesn't terminate the transaction via UT/TM then it'll remain associated with the transaction for its lifetime.

                  • 6. Re: Transaction not active & threads
                    marklittle

                    Pressed submit too early ...

                    [for its lifetime] or until disassociated explicitly.

                    • 7. Re: Transaction not active & threads
                      bentins

                      so if I have a runtime exception on a thread which was not handled correctly, this thread is returned to the thread pool with a dead transaction and everytime someone gets this thread from the pool he gets the dead transaction?

                      Is there a way to explicitly disassociate the transaction other then using the transaction commit or roll back?

                      • 8. Re: Transaction not active & threads
                        marklittle

                        Terminate it via UT/TM: if there's a problem the transaction will rollback and the transaction will be disassociated. Failing that, TM.suspend().