1 2 Previous Next 15 Replies Latest reply on Nov 6, 2009 5:41 PM by jeremiasce

    TransactionTimeout for SFSB

    marx3

      I have a problem with long running method.
      It's a method which fills datamodel with data. Sometimes it takes more than 5 minutes for this method to end.
      This is method of conversation-scoped bean.
      It seems that Seam for this method uses timeout attribute defined below:


      jboss-service.xml


         <!-- JBoss Transactions JTA -->
         <mbean code="com.arjuna.ats.jbossatx.jta.TransactionManagerService"
            name="jboss:service=TransactionManager">
            <attribute name="TransactionTimeout">300</attribute>
            <attribute name="ObjectStoreDir">${jboss.server.data.dir}/tx-object-store</attribute> 
         </mbean>
      



      But I cannot set it longer because it's global.
      I was trying to use @TransactionTimeout annotation on this method, but it doesn't work. It works only on stateless EJB components.


      How should I define timeouts for such method?


      Below is log:


      16:04:45,512 WARN  [arjLoggerI18N ?] [com.arjuna.ats.arjuna.coordinator.BasicAction_40] - Abort called on already aborted atomic action a0102f5:bda0:49d60e53:8f3
      16:04:45,512 WARN  [SeamPhaseListener ?] uncaught exception, passing to exception handler
      java.lang.IllegalStateException: Could not commit transaction
              at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:626)
              at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:605)
              at org.jboss.seam.jsf.SeamPhaseListener.handleTransactionsAfterPhase(SeamPhaseListener.java:343)
              at org.jboss.seam.jsf.SeamPhaseListener.afterServletPhase(SeamPhaseListener.java:243)
              at org.jboss.seam.jsf.SeamPhaseListener.afterPhase(SeamPhaseListener.java:194)
              at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:280)
              at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
              at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
              at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:73)
              at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
              at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
              at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:390)
              at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:517)
              at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
              at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
              at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
              at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
              at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
              at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
              at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
              at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
              at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
              at com.jamonapi.http.JAMonTomcatValve.invoke(JAMonTomcatValve.java:72)
              at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
              at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
              at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
              at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
              at java.lang.Thread.run(Thread.java:619)
      Caused by: java.lang.IllegalStateException: [com.arjuna.ats.internal.jta.transaction.arjunacore.inactive] [com.arjuna.ats.internal.jta.transaction.arjunacore.inactive] The transaction is not active!
              at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.rollbackAndDisassociate(TransactionImple.java:1473)
              at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.rollback(BaseTransaction.java:163)
              at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.rollback(BaseTransactionManagerDelegate.java:126)
              at org.jboss.tm.usertx.client.ServerVMClientUserTransaction.rollback(ServerVMClientUserTransaction.java:148)
              at org.jboss.seam.transaction.UTTransaction.rollback(UTTransaction.java:66)
              at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:622)
              ... 49 more


        • 1. Re: TransactionTimeout for SFSB
          swd847

          You may be able to do


          UserTransaction t = org.jboss.seam.transaction.Transaction.instance();


          which should get the transaction and then you can call the setTransactionTimeout method on it. Not sure if this will work though.

          • 2. Re: TransactionTimeout for SFSB
            marx3

            I see that in Gavin King post.
            Hovewer it doesn't work. You can't do that in Container Managed Beans

            • 3. Re: TransactionTimeout for SFSB
              sherkan777

              First line from google:



              http://www.jboss.org/community/docs/DOC-12439



              This should work

              • 4. Re: TransactionTimeout for SFSB
                marx3

                But it doesn't work.
                It's strange there is no annotation, but I have to define jboss.xml...


                For test I set global timeout in jboss-service.xml for 5 sec.
                Then i put a breakpoint in first line of my method in statefull bean and after 5 seconds I see in log


                13:35:09,742 WARN  [arjLoggerI18N ?] [com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator_4] TwoPhaseCoordinator.afterCompletion - returned failure for com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple@1c75848
                13:35:09,742 WARN  [arjLoggerI18N ?] [com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator_4] TwoPhaseCoordinator.afterCompletion - returned failure for com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple@7509f0
                


                • 5. Re: TransactionTimeout for SFSB
                  javacoryd

                  We did get this working, but needed to modify some seam code to make it work.  The reason it doesn't work ( in JBoss anyway ) is because you can't set the transaction timeout on the transaction after begin() is called on the transaction.


                  So, we extended the org.jboss.seam.transaction.Transaction class and overrode the getUserTransaction() method.  Before returning the transaction we set the transaction timeout.  In our case, we are setting the timeout from a request parameter ( we have a timeout parameter on our page ).  The page this is used on is responsible for loading very large data sets in to the database for the purpose of testing.


                  Hope this helps,


                  Cory.

                  • 6. Re: TransactionTimeout for SFSB
                    marx3

                    I've tested  it and at last it's working. It's pity that Seam doesn't allow to define it via method annotation

                    • 7. Re: TransactionTimeout for SFSB
                      marx3

                      How did you get request parameter in org.jboss.seam.transaction.Transaction class?

                      • 8. Re: TransactionTimeout for SFSB
                        javacoryd

                        FacesContext currentInstance = FacesContext.getCurrentInstance();
                        
                        if ( currentInstance != null ) {
                            Map<String, String> requestParameterMap = currentInstance.getExternalContext().getRequestParameterMap();
                            if ( requestParameterMap != null && !requestParameterMap.isEmpty() ) {
                                // Examine the request parameter here, if set
                                userTransaction.setTransactionTimeout( requestParameterInt * 60 );
                                ......





                        • 9. Re: TransactionTimeout for SFSB
                          marx3

                          I did it in the same way, and it works, hovewer I don't like this code.
                          1) request parameter is with form prefix, so I must iterate over requestParameterMap instead of simple get. It isn't optimized code.
                          2) getTransaction method is called many times (3-6) on single action. I set timeout on all transactions, but i'm not sure it's good idea
                          3) sometimes I get multiple error log entries with Cannot discover transaction status - it isn't expected behaviour
                          4)I would better like to annotate long running method with @TransactionTimeout, than creating hidden field with timeout attribute

                          • 10. Re: TransactionTimeout for SFSB
                            gonorrhea


                            I was trying to use @TransactionTimeout annotation on this method, but it doesn't work. It works only on stateless EJB components.



                            I see no requirement for SLSB only when using @TransactionTimeout in the following two links:


                            http://docs.jboss.org/ejb3/embedded/api/index.html?org/jboss/annotation/ejb/TransactionTimeout.html


                            http://www.jboss.org/community/docs/DOC-12439


                            So apparently it should work on SFSB using @TransactionTimeout (from what I just read)...

                            • 11. Re: TransactionTimeout for SFSB
                              marx3

                              Maybe it's Seam bug, because those transactions are managed by Seam. Would be nice to hear something from Seam team.

                              • 12. Re: TransactionTimeout for SFSB
                                marx3
                                • 13. Re: TransactionTimeout for SFSB
                                  brodequin.al.green.vec.virginia.gov

                                  Try the following annotations on the method of a SFSB:




                                  @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
                                  @TransactionTimeout(1500)
                                  public void method(){





                                  This seems to work to actually change the transaction timeout

                                  • 14. Re: TransactionTimeout for SFSB
                                    mtorres

                                    I had spent half of today trying to figure this out. Our requirement is a bit different because we're not using EJBs, so



                                    @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
                                    @TransactionTimeout(1500)




                                    is out of the question.


                                    I was initially calling Transaction.instance().setTimeout() inside my method, with no success, because at that point, the transaction has already begun.


                                    The solution that ended up working for me, is similar to Cory's approach which calls UserTransaction.setTimeout before UserTransaction.begin is called.


                                    The approach I used is a SeamFilter. It sets the timeout even before the transaction is started by SeamPhaseListener. Its currently configured by url-pattern, but I guess can be modified to read request parameters as well.


                                    @Startup
                                    @Scope(ScopeType.APPLICATION)
                                    @Name("transactionFilter")
                                    @BypassInterceptors
                                    @Filter(within="org.jboss.seam.web.exceptionFilter")
                                    @Install(value=false,precedence=Install.FRAMEWORK)
                                    public class TransactionFilter extends AbstractFilter {
                                         private Integer longTimeout;
                                         
                                         /* (non-Javadoc)
                                          * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
                                          */
                                         @Override
                                         public void doFilter(ServletRequest arg0, ServletResponse arg1,
                                                   FilterChain arg2) throws IOException, ServletException {
                                              try{
                                                   UserTransaction tx = new Transaction().getTransaction();
                                                   try{
                                                        if (longTimeout!=null && longTimeout>0){
                                                             try {
                                                                  tx.setTransactionTimeout(longTimeout);
                                                             } catch (SystemException e) {
                                                                  throw new ServletException(e);
                                                             }
                                                        }
                                                        arg2.doFilter(arg0, arg1);
                                                   }finally{
                                                        try {
                                                             //set to default, 0 restores it to default as per jta api.
                                                             tx.setTransactionTimeout(0);
                                                        } catch (SystemException e) {
                                                             throw new ServletException(e);
                                                        }
                                                   }
                                              }catch (NamingException e) {
                                                   throw new ServletException(e);
                                              }
                                         }
                                    
                                         /**
                                          * @return the longTimeout
                                          */
                                         public Integer getLongTimeout() {
                                              return longTimeout;
                                         }
                                    
                                         /**
                                          * @param longTimeout the longTimeout to set
                                          */
                                         public void setLongTimeout(Integer longTimeout) {
                                              this.longTimeout = longTimeout;
                                         }
                                    }




                                    and in components.xml


                                        <component name="transactionFilter" class="com.rfc.util.filters.TransactionFilter">
                                             <property name="regex-url-pattern">/longRunningPage.seam</property>
                                             <property name="longTimeout">1800</property>
                                        </component>



                                    Does anyone see any problems that may arise using this approach? Thanks for your input.


                                    1 2 Previous Next