10 Replies Latest reply on Jul 27, 2006 3:55 AM by peter_kaas

    Bug? Transaction timeout....

    modjoe23

      I have a message driven bean which is processing a transaction which cam sometimes run for hours. The main goal I am trying to acheive is to increase the transaction timeout from the default 300 seconds (5 mins) to somehere in hours. The code below demonstrates the number of things I have tried to acheive this, but I have been unsuccessful in every attempt. I am starting to think there may be a bug in one of the transaction annotations. Please help...thanks!

      - 1. Tried setting the context from setMessageDrivenContext which is called by the container. I then got the user transaction and tried to set that timeout to > 5 mins but that did not affect the 5 min default trans. timeout. (Please see commented code)

      - 2. Tried setting the @TransactionTimeout annotation to a value > 500 but that seems to do nothing...bug?

      - 3. Any other suggestions?

      @TransactionManagement(TransactionManagementType.BEAN)
      @TransactionAttribute(TransactionAttributeType.REQUIRED)
      @TransactionTimeout(value=800)
      public class MDBDataLoadTask implements MessageListener,MessageDrivenBean {
      private MessageDrivenContext ctx;

      public void onMessage(Message msg)
      {
      /*
      UserTransaction aUT = ctx.getUserTransaction();
      aUT.begin();
      aUT.setTransactionTimeout(360);
      */

      try
      {
      //Perform a task that will take about this long to run
      Thread.sleep(365000);
      //aUT.commit();
      }
      catch (Exception e)
      {
      /*try{
      aUT.setRollbackOnly();}
      catch(SystemException se){System.out.println(se.toString());}*/
      }
      }

      @Resource
      public void setMessageDrivenContext(MessageDrivenContext ctx) { this.ctx = ctx; }

      public void ejbRemove() {ctx=null;}
      }

        • 1. Re: Bug? Transaction timeout....
          modjoe23

          I know that I can change the default timeout value from the default 300 seconds in jta-service.xml but I am looking to change the transaction timeout for this transaction only. I've also read the spec but with no luck.

          Anybody out there?? Please help!

          • 2. Re: Bug? Transaction timeout....
            peter_kaas

            Any change if you add the @TransactionTimeout to the method instead of the class? I have experienced the same problems you describe but ended up changing the default timeout...

            • 3. Re: Bug? Transaction timeout....
              modjoe23

              Hi Peter,

              No that hasn't solved it for me. Please let me know if you find a solution to this problem. Thanks.

              • 4. Re: Bug? Transaction timeout....
                joed

                I found this in the XDoclet reference:

                http://xdoclet.sourceforge.net/xdoclet/tags/jboss-tags.html

                If you look for transaction-timeout, it seems to indicate that the change only applies if the method starts the transaction. Since that's never the case with MDB using REQUIRED, perhaps if you change it to REQUIRES_NEW you might get what you want.

                I've got the same issue, and I'm going to try this change soon. I'll post my results once I get a chance to try it out, but I thought I'd pass this guess along first, since you seemed desperate :-)

                • 5. Re: Bug? Transaction timeout....
                  modjoe23

                  Joed,

                  Thank you for that. I must have missed it. I will try that as soon as I can and post my results as well.

                  • 6. Re: Bug? Transaction timeout....
                    joed

                    Sigh. It didn't work. If I had thought before trying I would have realized it couldn't. I imagine that the container has its own transaction for the queue, which is timing out because the onMessage() method is taking a long time, even though *my* transaction has a longer time out.

                    I think I'm going to just spawn a thread in the onMessage() to handle the work, and return immediately. I lose all opportunity for resends, but c'est la vie.

                    • 7. Re: Bug? Transaction timeout....
                      modjoe23

                      That's exactly why I tried to a handle to that transaction and increase it's timeout myself, but that didn't work. There has to be a way to do it!

                      • 8. Re: Bug? Transaction timeout....
                        thhal

                        So, in essence there is no way to control the transaction timeout for an MDB unless you change the global transaction timeout? If that's true, I would consider it a fairly serious flaw in JBoss.

                        A work around involving new threads won't help me much since it's essential that the popping of the queue must is synchronized with the many inserts that causes the timeout.

                        • 9. Re: Bug? Transaction timeout....
                          epbernard

                          One a JIRA feature request please.

                          • 10. Re: Bug? Transaction timeout....
                            peter_kaas

                            What if you mark your MDB with:

                            @TransactionManagement(TransactionManagementType.BEAN)
                            


                            and then roll your own transaction like:

                            @Resource
                            private transient MessageDrivenContext context;
                            
                            ...
                            
                            UserTransaction ut = null;
                            
                            try {
                             ut = context.getUserTransaction();
                             ut.setTransactionTimeout(TIMEOUT);
                             ut.begin();
                            
                             // Do your stuff
                            
                             ut.commit();
                            } catch (Throwable ex) {
                             try { if (ut != null) ut.rollback(); } catch (Throwable ex2) { }
                            
                             ...
                            }