6 Replies Latest reply on Nov 9, 2010 12:14 PM by Sean Ballow

    POJO transaction timeout

    Damian Harvey Apprentice

      I have a couple of methods that do some chunky processing and need a longer transaction timeout.


      I know that I can:



      • Change the global transaction timeout in jboss-service.xml; or

      • Create an SLSB and annotate it with @TransactionTimeout



      But is there anyway to set the timeout on a POJO, possibly something in line with the @Transactional annotation? I'm using CMT so I can't set the timeout programmatically (afaik?).


      Cheers,


      Damian.

        • 1. Re: POJO transaction timeout
          System Administrator Expert

          This wiki is unfortunately outdated (somewhat typical of JBoss), but is useful:


          http://wiki.jboss.org/wiki/TransactionTimeout


          Also, you can use the annotation you mentioned above:


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


          And refer to Mike Keith's book on EJB3/JPA for coverage on the UserTransaction interface, there is a setTransactionTimeout() method that may be useful unless you want to set it globally.


          You may also be able to process the DB transaction(s) asynchronously, but not sure that will help in your use case or not...


          Also, you can turn off transaction support

          (transaction type = @NOT_SUPPORTED)

          for those methods, if that works for you...

          • 2. Re: POJO transaction timeout
            Damian Harvey Apprentice

            Thanks Arbi. I've seen those links.


            After reading the API it looks like I can turn off transaction support for a POJO method like this:


            @Transactional(TransactionPropagationType.NEVER)
            


            Even so, in the ideal world I would be able to do something like this:


            @Transactional(TransactionPropagationType.REQUIRED, timeout = 600)
            


            Cheers,


            Damian.

            • 4. Re: POJO transaction timeout
              Samuel Doyle Apprentice

              It does not look as if the @TransactionTimeout works on non-EJB3 POJOS


              From the api:


              Annotation for specifying the transaction timeout of an EJB business method


              I have cases where even using this annotation on a POJO will result on a timeout less then the time I specify. Is there an alternate way of doing this in Seam?


              Thanks in advance.

              • 5. Re: POJO transaction timeout
                Julien Kronegg Novice

                On a project using JTA transactions and POJO entities (no EJB3), we use the following solution:


                @Transactional
                public void myLongRunningMethod() {
                
                    // set the transaction timeout
                    try {
                        int transactionTimeoutSeconds = 1000;
                        log.info("setting transaction timeout to "+transactionTimeoutSeconds+" seconds");
                        ((javax.transaction.UserTransaction)org.jboss.seam.transaction.Transaction.instance()).setTransactionTimeout(transactionTimeoutSeconds);
                    } catch (SystemException e1) {
                        // failed to set the transaction timeout => just log some content
                        e1.printStackTrace();
                    }
                
                    // my long running code
                    ...
                }
                

                • 6. Re: POJO transaction timeout
                  Sean Ballow Newbie

                  JBOSS 5.1.0
                  SEAM 2.2.0


                  configure the timeout for your CMT in /default/deploy/transaction-jboss-beans.xml the default is 5 minutes (300 seconds)



                  <property name="transactionTimeout">300</property>



                  increase the duration to whatever length of time you think it should take.


                  regular pojo with asynchronous method call, not ejb just seam component



                  @Asynchronous
                  @Transactional(TransactionPropagationType.REQUIRED)    
                  public void doSomethingAsynchronously(List<Object> list) {
                      //do long running thing here on list
                  }



                  this works for us on a large set of records like a mini batch process.