TransactionTimeout(事务超时)

Transaction timeout (unit is always seconds) can be configured in various ways:

This argument is the same no matter if you are using JBossTM(<=4.0.5) or JBossJTA-Arjuna(>=4.2).

 

  • Globally: You can change this behavior globally by modifying the TransactionManagerService in /conf/jboss-service.xml (or /deploy/jta-service.xml for 4.0.3)

 

Version <= 4.0.5

<mbean code="com.arjuna.ats.jbossatx.jta.TransactionManagerService"
   name="jboss:service=TransactionManager">

   <attribute name="TransactionTimeout"> 300</attribute>    ...
</mbean>

Version >= 4.2

<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>

This part is the same for either JBossTM or JBossJTA and is the same for ejb2 and ejb3

  • Per-method basis: Modifying the <transaction-timeout> element inside the <method> element of a session or entity bean. This is located in the META-INF/jboss.xml deployment descriptor of a session bean. When the transaction timeout is specified at the method level, it overrides the default timeout. Further information about this element can be found in jboss-x.x.x/docs/dtd/jboss_4_0.dtd. Example taken from the testsuite:

<?xml version="1.0"?>

<jboss>
  <enterprise-beans>     <session>
      <ejb-name> TxTimeout</ejb-name>
      <jndi-name> jbosstest/tm/TxTimeout</jndi-name>
      <exception-on-rollback> true</exception-on-rollback>       <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>
  • Using BMT: Calling javax.transaction.UserTransaction.setTransactionTimeout(int seconds). Please, be aware that this only applies to transactions started after this invocation on the same thread. Example:

UserTransaction ut = (UserTransaction)ctx.lookup("java:comp/UserTransaction"
);
ut.setTransactionTimeout(20);
ut.begin();
...
ut.commit();
  • Using it with EJB3 annotations..

For MBDs, you can specify it as an activation configuration that applies to the entire bean:

@ActivationConfigProperty(propertyName="transactionTimeout"
, propertyValue="1"
)

For the rest of beans, you can use @TransactionTimeout annotation that can be applied either at class level or method level:

@TransactionTimeout(1500)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值