5 Replies Latest reply on Apr 22, 2003 2:20 PM by divine_comedy

    EJB and Transaction in JBoss, urgent help required

    divine_comedy

      Hi everyone,

      I am currently using JBoss 3.0.4. I have an MBean that does the following :
      Collection test = findAllBeansWithStatusReady

      later on in the code (about 6 lines away), I iterated
      through the collection and did
      bean.getStatus() because the bean's status might have changed.

      By the way I am not starting any UserTransaction and the Bean has transaction attribute : Required.

      With this condition, I sometimes get the following :
      Transaction XidImpl [FormatId=257, GlobalId=miami//5, BranchQual=] timed out. status=STATUS_ACTI
      VE
      [ftp/FtpBean] Transaction XidImpl [FormatId=257, GlobalId=miami//7, BranchQual=] timed out. status=STATUS_ACTI
      VE
      [BeanLock] Thread[RMI TCP Connection(10)-192.168.0.89,5,RMI Runtime]Saw rolled back tx=TransactionImpl:XidImpl
      [FormatId=257, GlobalId=miami//7, BranchQual=] waiting for txLock
      [ftp/FtpBean] TRANSACTION ROLLBACK EXCEPTION:Transaction marked for rollback, possibly a timeout; nested excep

      This is not the real message, I just grabbed it from another post in the board, but it's pretty much the same thing. BeanLock, Transaction Rollback.

      Any explanations for this ? How do I track which beans have already been enlisted in a transaction ?

        • 1. Re: EJB and Transaction in JBoss, urgent help required

          There could be any number of causes for this.

          1) There were some fixes done in this area so
          try 3.0.7
          2) You haven't implemented the primary key
          correctly.
          3) Some other thread is doing a long running
          process on the bean and thereby locking it.

          The default locking strategy is pessimisstic.

          Regards,
          Adrian

          • 2. Re: EJB and Transaction in JBoss, urgent help required
            divine_comedy

            I've experimented around further with this, and I need some input regarding the use of UserTransaction and its semantics. What happens if I did the following :
            userTransaction.begin();
            bean.getStatus();

            and at the same time, another thread runs that does
            findAllBeansWithStatusXXX;
            iterate through the beans
            bean.getStatus();

            the threads ran in different MBeans.

            My experiment causes a lot of transaction timeouts and beanlocks. Am I doing something really wrong here ?

            • 3. Re: EJB and Transaction in JBoss, urgent help required

              The first invoke bean.getStatus() locks
              the bean to the user transaction.
              It will remain locked until the user transaction
              is committed or rolled back.
              The other transactions will wait until the lock
              is released or the transaction times out.

              If you didn't intend to lock, try searching
              for <read-only> methods and other
              locking policies.

              They are explained in more detail in the $10 docs.

              Regards,
              Adrian

              • 4. Re: EJB and Transaction in JBoss, urgent help required
                divine_comedy

                Thanks Adrian. That's what I thought should happen as well. I've run another experiment where I only let the first MBean run. With the same code running, here's what I got, the first time the MBean runs it is fine all the way until I do a UserTransaction.commit. 5 mins later, the MBean runs again and I got this exception : "Transaction already active, cannot nest transactions".

                I thought a commit should release locks on all beans involved in the transaction. I dig around in the logs and there doesn't seem to be an exception caused by a transaction.commit or transaction.rollback.

                Just for reference the code :
                try {
                ut.begin();
                order.getStatus();
                .... some code
                ut.commit();
                } catch (SomeException e) {
                if( ut.getStatus != "NO_TRANSACTION") {
                ut.rollback();
                }
                }

                • 5. Re: EJB and Transaction in JBoss, urgent help required
                  divine_comedy

                  Forget it, I finally fixed it. Turns out that I forgot to do a commit() in one of the early return statement so I was having a transaction leak.

                  However, I wonder what happens if a commit or rollback fails ? Can anybody shed some light on this ?
                  Would all the beans that have been locked be released ?