Announcement Announcement Module
Collapse
No announcement yet.
Setting a Global Transaction timeout using JTA? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Setting a Global Transaction timeout using JTA?

    Hi - Using Weblogic 8.1, I have tried to set the global tx timeout using Spring (rather than BEA config.xml). I looked up the UserTransaction (and tried TransactionManager) from JNDI and set the timeout on it. I then set this as the userTransaction (and transactionManager) property that was used inside WeblogicJtaTransactionManager. The WeblogicJtaTransactionManager was then set in the TransactionProxyFactoryBean. It does not seem to work, I am still getting the BEA domain default of 30 seconds. If anyone can assist, I would greatly appreciate it. Thanks!

  • #2
    shorecode,

    You can't use that approach. UserTransaction is an interface supposed to be used to manipulate the current transaction context, i.e. the setTransactionTimeout sets the timeout of the current transaction. This is something that Spring itself needs to do, as it's demarcating transactions.

    I don't know how you are actually transactionally wrapping your service layer, but presumably you are using the standard declarative TransactionProxyFactoryBean with transaction attributes defined. Take a look at the JavaDoc for TransactionAttributeEditor to see how you can add a timeout on the transaction values, along with the propagation values you normally use. The format is:

    PROPAGATION_NAME,ISOLATION_NAME,readOnly,timeout_N NNN,+Exception1,-Exception2

    e.g. in a declaration like:
    PROPAGATION_REQUIRED,-MyCheckedException
    to specify that transactions are required, and you want to rollback on MyCheckedException, you can actually also insert a timeout, and specify readOnly.

    Comment


    • #3
      Thanks Colin! I found this out through some testing. Yes, I am using TransactionProxyFactoryBean. I am familiar with how Spring allows you to set transaction attributes per method. I was more wondering at the global level. Suppose I did the below, what timeout would win?

      <bean
      id="abstractTransactionalBean"
      abstract="true"
      class="org.springframework...TransactionProxyFacto ryBean">

      <property name="transactionAttributes">
      <props>
      <prop key="*">timeout_20</prop>
      </props>
      </property>
      </bean>


      <bean id="myService" parent="abstractTransactionalBean" lazy-init="true">
      <property name="target">
      <bean class="MyServiceImpl"/>
      </property>

      <property name="transactionAttributes">
      <props>
      <prop key="update">PROPAGATION_REQUIRED,timeout_500</prop>
      </props>
      </property>
      </bean>

      Comment


      • #4
        Yes, it would work fine to define one value in the base template, abstract, bean definition, and then override it in children. Note however that the propagation setting is manadatory (it's the only mandatory part of the string actually), so you'd have to add PROPAGATION_REQUIRED (or whatever is appropropriate) to the base definition, along with the timeout. Then child bean definitions override the entire string if needed.

        Comment


        • #5
          Ok, one more question for clarification. Let's say I specify Propagation Behavior of PROPAGATION_SUPPORTS and timeout of 30 at the parent level.

          What happens (Propagation Behavior and timeout) in a bean that has that as its parent in below scenarios:

          //method A in myServiceImpl
          <prop key="A">PROPAGATION_REQUIRED,timeout_500</prop>
          --> result is PROPAGATION_REQUIRED,timeout_500 ??

          //method B in myServiceImpl
          <prop key="B">PROPAGATION_REQUIRED</prop>
          --> result is PROPAGATION_REQUIRED,timeout_30 ??

          //method C in myServiceImpl
          <!-- no entry in xml -->
          --> result is PROPAGATION_SUPPORTS,timeout_500 ??

          //method D in myServiceImpl
          <prop key="D">PROPAGATION_NEVER</prop>
          --> result is PROPAGATION_NEVER,timeout_30 ?? (but since there is no TX then the timeout is effectively ignored)

          Comment


          • #6
            I meant timeout_30 for method C.

            Comment


            • #7
              When you do specify a transactionAttributes property in the child bean definition, that overrides the entire property from the parent. We're talking about a base definition for the property, and an override (or lack of override) in the child. It knows nothing about transactions, and any other use of the particular property.

              So if you need a timeout in the child, and specify a transaction attribute, then you need to specify a timeout there too.

              Comment

              Working...
              X