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:
- Locking a row via SQLDeveloper,
- Try to update the same row via the app,
- Keeps waiting for the lock,
- 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.
Most of the TransactionsEssentials JTA settings can be tweaked using the
jta.propertiesfile (placed at the root of your classpath) ortransactions.properties(also can be placed in your main resources folder)The configurations of interest are:
com.atomikos.icatch.max_timeoutcom.atomikos.icatch.default_jta_timeoutSo if you configured your
transactions.propertiesfile with:It should do the trick to allow for a maximum of 10 seconds.
See: Atomikos - JtaProperties - Transaction manager