3 Replies Latest reply on Aug 10, 2004 10:24 PM by starksm64

    Transaction timeout configuration for a specific Stateless S

    herbherby

      Hello,

      I am trying to figure out where in the jboss.xml I can set the transaction timeout value for a specific stateless session bean. I can only find the 'TransactionTimeout' attribute of the TransactionManagerService which applies to all session beans. Could anybody help me with that ??

      Thanx in advance ...

      PS: I am using JBoss Version 3.2.3

        • 1. Re: Transaction timeout configuration for a specific Statele
          cvandyck

          You will only be able to do this if you use bean managed transactions.

          In your session bean, here's some starter methods that you can use to start and end your transactions:

          protected int beginTransactionIfRequired(int timeoutInSeconds) {
           UserTransaction tran = this.sessionContext.getUserTransaction();
           int initialTranStatus;
           try {
           initialTranStatus = tran.getStatus();
           switch (initialTranStatus) {
           case Status.STATUS_ACTIVE:
           // we are ok just using the current transaction.
           break;
           case Status.STATUS_NO_TRANSACTION:
           // create a new transaction.
           try {
           this.sessionContext.getUserTransaction().setTransactionTimeout(timeoutInSeconds);
           tran.begin();
           } catch (NotSupportedException e) {
           throw new EJBException("Unable to start transaction: " + e.getMessage());
           }
           break;
           default:
           throw new EJBException("Transaction status invalid, status is: " + initialTranStatus);
           }
           } catch (SystemException e) {
           throw new EJBException("Unable to begin transaction",e);
           }
           return initialTranStatus;
           }
          
           protected void completeTransactionIfRequired(int initialTransactionStatus) {
           UserTransaction tran = this.sessionContext.getUserTransaction();
          
           if (initialTransactionStatus == Status.STATUS_NO_TRANSACTION) {
           try {
           if (tran.getStatus() == Status.STATUS_MARKED_ROLLBACK) {
           tran.rollback();
           } else {
           tran.commit();
           }
           } catch(Exception e) {
           throw new EJBException("Unable to complete transaction",e);
           }
           }
           }
          
          


          • 2. Re: Transaction timeout configuration for a specific Statele
            herbherby

            Thanx Collin, I will try that, even though I can't understand why this feature isn't possible with Container Managed Transactions !? ...

            • 3. Re: Transaction timeout configuration for a specific Statele
              starksm64

              jboss-3.2.5 supports method level tx timeouts.

              <?xml version="1.0"?>
              <jboss>
              
               <enterprise-beans>
               <session>
               <ejb-name>TxTimeout</ejb-name>
               <jndi-name>jbosstest/tm/TxTimeout</jndi-name>
               <method-attributes>
               <method>
               <method-name>testOverriddenTimeoutExpires</method-name>
               <transaction-timeout>5</transaction-timeout>
               </method>
               <method>
               <method-name>testOverriddenTimeoutDoesNotExpire</method-name>
               <transaction-timeout>20</transaction-timeout>
               </method>
               </method-attributes>
               </session>
               </enterprise-beans>
              
              </jboss>