将JTA事务超时从默认更改为自定义 [英] change jta transaction timeout from default to custom
问题描述
我正在使用Atomikos进行JTA交易. 我对JTA进行了以下设置:
I am using Atomikos for JTA transaction. I have following setting for JTA:
UserTransactionImp userTransactionImp = new UserTransactionImp();
userTransactionImp.setTransactionTimeout(900);
但是当我的代码执行JTA事务时,如果花费超过5分钟(这是默认值),则会引发异常:
but when my code perform JTA transaction, then if it takes more than 5 minutes (which is default value) then it throws exception:
Caused by: com.atomikos.icatch.RollbackException: Prepare: NO vote
at com.atomikos.icatch.imp.ActiveStateHandler.prepare(ActiveStateHandler.java:231)
at com.atomikos.icatch.imp.CoordinatorImp.prepare(CoordinatorImp.java:681)
at com.atomikos.icatch.imp.CoordinatorImp.terminate(CoordinatorImp.java:970)
at com.atomikos.icatch.imp.CompositeTerminatorImp.commit(CompositeTerminatorImp.java:82)
at com.atomikos.icatch.imp.CompositeTransactionImp.commit(CompositeTransactionImp.java:336)
at com.atomikos.icatch.jta.TransactionImp.commit(TransactionImp.java:190)
... 25 common frames omitted
它似乎采用了默认的jta事务超时(即使我明确地设置了超时(至15分钟/900秒).
it looks like its taking the default jta transaction timeout (even though i am setting timeout explicitely (to 15 minutes/900 seconds).
我尝试在application.properties文件中使用以下属性,但是它仍采用默认超时值(300秒).
I tried using following properties in application.properties file however it still takes the default timeout value(300 seconds).
spring.jta.atomikos.properties.max-timeout=600000
spring.jta.atomikos.properties.default-jta-timeout=10000
我也尝试过以下属性,但没有运气:
I have also tried with below property but no luck:
spring.transaction.default-timeout=900
有人可以建议我是否需要其他设置吗?我正在使用Wildfly插件,Spring Boot和Atomikos api进行JTA交易.
Can anyone suggest if I need any other setting? I am using wildfly plugin, spring boot and atomikos api for JTA transaction.
推荐答案
来自 Atomikos文档:
com.atomikos.icatch.max_timeout
指定事务允许的最大超时时间(以毫秒为单位).默认值为300000.这意味着对UserTransaction.setTransactionTimeout()的调用的值大于此处配置的值,将被最大化为该值.对于4.x或更高版本,值0表示没有最大值(即,允许无限超时).
Specifies the maximum timeout (in milliseconds) that can be allowed for transactions. Defaults to 300000. This means that calls to UserTransaction.setTransactionTimeout() with a value higher than configured here will be max'ed to this value. For 4.x or higher, a value of 0 means no maximum (i.e., unlimited timeouts are allowed).
实际上,如果您查看Atomikos库源代码(对于4.0.0M4版本和
Indeed, if you take a look at the Atomikos library source code (for both versions 4.0.0M4 and 3.7.0), in the createCC
method from class com.atomikos.icatch.imp.TransactionServiceImp
you will see:
387: if ( timeout > maxTimeout_ ) {
388: timeout = maxTimeout_;
389: //FIXED 20188
390: LOGGER.logWarning ( "Attempt to create a transaction with a timeout that exceeds maximum - truncating to: " + maxTimeout_ );
391: }
因此,任何指定更长事务超时的尝试都将限制为maxTimeout_
,如果未指定,则默认值在初始化期间设置为300000.
So any attempt to specify a longer transaction timeout gets capped to maxTimeout_
which has a default value of 300000 set during initialization if none is specified.
您可以使用以下命令将com.atomikos.icatch.max_timeout
设置为JVM参数:
You can set the com.atomikos.icatch.max_timeout
as a JVM argument with:
-Dcom.atomikos.icatch.max_timeout=900000
,或者您可以使用中指定的高级案例配方Atomikos文档中的>"Spring的配置"部分.
or you could use The Advanced Case recipe specified in the Configuration for Spring Section from the Atomikos documentation.
这篇关于将JTA事务超时从默认更改为自定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!