3 Replies Latest reply on Sep 16, 2010 3:46 AM by wdfink

    Working around transaction timeouts

    dfisher

      Using JBoss 5.1.0

       

      I've got a long running clean up task that repeatedly invokes a stateless session bean.

      The problem I'm having is that the task takes longer than 5 minutes to run, which is the default transaction timeout.

      Rather than change the default value or define a custom value on the SSB, I'm trying to wire things up so each SSB call uses it's own transaction.

      My current design looks like:

       

      MBean

        invoke Task [SSB with @TransactionAttribute(NEVER)]

                invoke Search [SSB with @TransactionAttribute(REQUIRED)], look up entities to operate on

                for each entity

                  invoke Operation [SSB with @TransactionAttribute(REQUIRED)], perform operation

       

      My expectation is that Task does not have a transaction.

      The Search transaction will commit when all entities are found.

      A new transaction will run and commit for each invocation on Operation.

      However, what occurs is that all operations rollback after 5 minutes.

       

      Can anyone explain the correct way to do this?

      Thanks.

        • 1. Re: Working around transaction timeouts
          wdfink

          I aggree to your expectation.

          Do you have switched on TRACE for the transaction manager? (don't know the exact package ATM)

          Or you might use REQUIRES_NEW for both (which should be indeed the same result in your case)

          • 2. Re: Working around transaction timeouts
            dfisher

            After some research I'm not certain I can get the behavior I need.

            I was able to isolate transactions for a specific use case where I know the invoking client does not have a transaction:

             

              invoke Task [SSB with @TransactionAttribute(NOT_SUPPORTED)]

                      invoke Search [SSB with @TransactionAttribute(REQUIRED)], look up entities to operate on

                      for each entity

                        invoke Operation [SSB with @TransactionAttribute(REQUIRED)], perform operation

             

            This does execute the Search and Operation methods in separate transactions and allow run times greater than the default timeout for the Task method.

            However, if the client invoking Task is not an MBean, but rather another business component, it's transaction will be suspended while the Task runs and will timeout after 5 minutes.

             

            So am I understanding this correctly?

            You can gain some control over transaction timeouts, but only if you know your clients are not using a transaction.

            • 3. Re: Working around transaction timeouts
              wdfink

              Yes, you are right.

              In your case the clients transaction will be suspended and if the new transaction will take more time than the clients-Tx-timeout the result is

              that your (inner) Tx will be successful commited and the outer Tx will be rolled back.