3 Replies Latest reply: Apr 13, 2012 6:07 AM by Bob Kung RSS

    EJB thread not interrupted after transaction timeout

    Bob Kung Newbie

      Hi all,

       

      I was doing a MDB timeout test

      1) I have a stls(ABean) bean and a mdb (BBean). BBean invokes ABean.

      2) set @ActivationConfigProperty(propertyName = "transactionTimeout", propertyValue = "10") to BBean

      3) BBean will reply a message to a queue(replyQueue) at the end of onMessage(), if any exception throws, current message will fall to dlq.

      4) ABean will sleep 20 seconds which will cause BBean timeout.

      5) Redelivery Delay: 0, Max Delivery Attempts: 1

      6) running on JBoss AS 7.1.0 final

       

       

       

      Expect result is

      Transaction timeout --> transaction rollback --> redelivery ---> transaction timeout again --->transaction rollback again ---> send message to dlq

       

      Actual result is

      Transaction timeout --> transaction rollback --> send message to dlq---> ABean and BBean keep running till ABean wake up  --> reply message to replyQueue.

                                                                                          --->redeliver --> transaction timeout --> exception catch "The transaction is not active!" --->reply message to replyQueue

       

       

      Seems the timeout just only rollback the tx transaction, but will not terminate the running thread or trigger redelivery.

       

      Is there something wrong I have? Please help!! Many thanks!

      ________________________________________________________________________________________________________________________________________________

       

      Additional test result

      After I set the Max Delivery Attempts to 3

      I found that the exception message redeliver 3 times, all of them hit the same exception "Unable to call after delivery: javax.resource.spi.LocalTransactionException: javax.transaction.RollbackException: ARJUNA016063: The transaction is not active!", however each redeliver message replyed and only one dlq was added.

       

      sendQueue 1

      replyQueue 3

      dlq              1

       

      So I revised my above situation. Is this a bug?

        • 1. Re: MDB keep running after transaction timeout
          Bob Kung Newbie

          I think here is an interesting article related to my thread

          • 3. Re: EJB thread not interrupted after transaction timeout
            Bob Kung Newbie

            So far I havn't found any elegent solution, however, I have a workaround, though it will introduces non-business code into your MDB.

             

            1) Inject EJBContext to your MDB

            2) Use ejbContext.getRollbackOnly() method to check whether the current transaction already rollback before continue process. If current transaction has been canceled, skip the following process till the end.

             

            This solution should be safe in only database operating situation, meanwhile there still has a drawback for this solution.  Please look at the following situation.

            1) The some operations to a share resource which is not rollbackable, such as writing strings to a file in this transaction.

            2) Redelivery Delay is 0 and Max Delivery Attempts more than 1

            Once the transaction timeout, JMS will redeliver the message, but the previous message still on processing which is writing strings to a file. At this time, the file is operating by 2 threads and this may cause error. So it should be considered how to handle the resource conflict in this case.

             

            Am I missing sth? please comment.