0

I'm trying to reduce the default timeout of 300 seconds with JTA + Atomikos. However, it's not working as it keeps taking 300 seconds to time out.

What I want to do is:

  • UserTransaction: Set the timeout to 10 seconds.
  • UserTransactionManager: Set timeout to 10 seconds.
UserTransactionImp userTransaction = new UserTransactionImp();

userTransaction.setTransactionTimeout(10);

// ...

UserTransactionManager transactionManager= new UserTransactionManager();
transactionManager.setTransactionTimeout(10); // may not be necessary as I do set this on the transaction

// ...

JtaTransactionManager jtaTransactionManager = new JtaTransactionManager(userTransaction,transactionManager);

// ...

TransactionTemplate templ = new TransactionTemplate(jtaTransactionManager, new DefaultTransaction());

templ.execute(callback -> {
  // code to update the DB
})

How I am testing this:

  1. Locking a row via SQLDeveloper,
  2. Try to update the same row via the app,
  3. Keeps waiting for the lock,
  4. Times out eventually.

I expected this to time out after 10 seconds based on the setting I have done above. However, it keeps on waiting for 300 seconds before it times out.

Not sure where else I need to configure this.

u-ways
  • 6,136
  • 5
  • 31
  • 47
karansardana
  • 1,039
  • 2
  • 9
  • 8

1 Answers1

0

Most of the TransactionsEssentials JTA settings can be tweaked using the jta.properties file (placed at the root of your classpath) or transactions.properties (also can be placed in your main resources folder)

The configurations of interest are:

Property name Description Since
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). NOTE: as of 5.0, using 0 interferes with recovery. Instead, use Long.MAX_VALUE to specify unlimited. 3.x, 4.x
com.atomikos.icatch.default_jta_timeout The default timeout for JTA transactions (optional, defaults to 10000 ms) 3.4, 4.x

So if you configured your transactions.properties file with:

# transactions.properties
# .../src/main/resources/transactions.properties
# Max timeout for any JTA transactions. (10 seconds)
com.atomikos.icatch.max_timeout=10000
# Default timeout for any JTA transactions. (5 seconds)
com.atomikos.icatch.default_jta_timeout=5000

It should do the trick to allow for a maximum of 10 seconds.

See: Atomikos - JtaProperties - Transaction manager

u-ways
  • 6,136
  • 5
  • 31
  • 47