7 Replies Latest reply on Aug 13, 2013 6:29 AM by sfcoy

    Singleton Bean Transaction Management

    method_ben_qc

      Hi,

       

       

      Anyone know if the annotation @TransactionTimeout is honnored on a method annoted with @PostConstruct in a startup singleton bean ?

      My Singleton Bean:

       

       

      import javax.annotation.PostConstruct;

      import javax.annotation.PreDestroy;

      import javax.ejb.Singleton;

      import javax.ejb.Startup;

      import javax.ejb.TransactionAttribute;

      import javax.ejb.TransactionAttributeType;

       

       

      @Startup

      @Singleton

      public class StartupBean

      {

           private static final Log LOGGER = LogFactory.getLog(StartupBean.class);

       

           @PostConstruct

           @TransactionTimeout(1800000)

        @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)

           public void init()

           {

            // Call another EJB.

           }

      }

       

       

      My transaction reaches is timeout after 5 minutes which is the setting in my standalone.xml:

       

       

      <subsystem xmlns="urn:jboss:domain:transactions:1.1">

                  <core-environment>

                      <process-id>

                          <uuid/>

                      </process-id>

                  </core-environment>

                  <recovery-environment socket-binding="txn-recovery-environment" status-socket-binding="txn-status-manager"/>

                  <coordinator-environment default-timeout="300"/>

      </subsystem>

       

       

      Thank you

        • 1. Re: Singleton Bean Transaction Management
          jaikiran

          What does the import statement for @TransactionTimeout look like?

          • 2. Re: Singleton Bean Transaction Management
            method_ben_qc

            import org.jboss.ejb3.annotation.TransactionTimeout;

            • 3. Re: Singleton Bean Transaction Management
              papangdim

              Hi,

               

              I face the same problem but what I think I noticed was that if I had set my timeout to something less than 5 minutes, (say 30 seconds) the timeout was honoured and the transaction reaper kicked in exactly 30 sec after the transaction had started. So I then changed the timeout back to 30 minutes hoping that this would work but it seems that the transaction reaper kicked in after 5 minutes as defined in the xml file.

               

              Thank you

              • 4. Re: Singleton Bean Transaction Management
                erhard

                Hi,

                 

                Is this intended behaviour? The default-timeout from the standalone.xml can be shortend with the annotation, but not increased?

                I have a similar problem with a long PostConstruct-method in a singleton using EAP6.0.1

                 

                Erhard

                • 5. Re: Singleton Bean Transaction Management
                  sfcoy

                  Do your initialisation operations really need to be transactional?

                   

                  Are they performing database operations or sending JMS messages?

                  • 6. Re: Singleton Bean Transaction Management
                    erhard

                    In this particular case, I could do without transactions. We just call one existing EJB and the first call to any of our EJBs takes a long time for reasons I could explain in private if anybody is interested. All our EJBs are just @Stateless and therefore they open transactions.

                    This might or might not be clever, but I think it is not the isssue. I find it confusing that the annotation does not work as I expected and that apearently one can decrease the timeout, but not increase it. I didn't try it but mybe its not even related to Singletons, since its just the CMTTxInterceptor that handles the Transaction? Therefore my question is wether this is intended or a bug.

                    • 7. Re: Singleton Bean Transaction Management
                      sfcoy

                      I can't remark on the behaviour of the annotation.

                       

                      However, long running transactions can cause all kinds of issues and you should design around avoiding them if possible.

                       

                      If you're processing an import file for example, consider processing it (say) fifty rows at a time and execute multiple short transactions instead.