change jta transaction timeout from default to custom

最后都变了- 提交于 2019-12-19 09:04:02

问题


I am using Atomikos for JTA transaction. I have following setting for JTA:

UserTransactionImp userTransactionImp = new UserTransactionImp();
userTransactionImp.setTransactionTimeout(900);

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

it looks like its taking the default jta transaction timeout (even though i am setting timeout explicitely (to 15 minutes/900 seconds).

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

Can anyone suggest if I need any other setting? I am using wildfly plugin, spring boot and atomikos api for JTA transaction.


回答1:


From the Atomikos documentation:

com.atomikos.icatch.max_timeout

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

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

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.

You can set the com.atomikos.icatch.max_timeout as a JVM argument with:

-Dcom.atomikos.icatch.max_timeout=900000

or you could use The Advanced Case recipe specified in the Configuration for Spring Section from the Atomikos documentation.




回答2:


I've resolved similar problem where configuration in application.yml (or application. properties) of Spring Boot did not get picked up.

There was even a log that I later found mentioned in official docs.

However, I added transactions.properties file (next to the application.yml) where I set mine desired properties.

# Atomikos properties

# Service must be defined!
com.atomikos.icatch.service = com.atomikos.icatch.standalone.UserTransactionServiceFactory

# Override default properties.
com.atomikos.icatch.log_base_dir = ./atomikos

Some properties can be set within transactions.properties and other within jta.properties file.



来源:https://stackoverflow.com/questions/45282120/change-jta-transaction-timeout-from-default-to-custom

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!