使用Atomikos减少JTA的交易超时
我正在尝试使用JTA + Atomikos减少300秒的默认超时。但是,它没有工作,因为它不断需要300秒的时间。
我想做的是:
userTransaction
:将超时设置为10秒。userTransactionManager
:将超时设置为10秒。
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
})
我如何测试此问题:
- 通过SQLDEVEVELER锁定一行,
- 尝试通过应用程序更新同一行,
- 不断等待锁,
- 最终会出来。
我希望根据上述设置在10秒后止步。但是,它一直在等待300秒之前。
不确定我需要在哪里配置此。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以使用
jta.properties
file(放置在classPath的根部)或transactions.properties
(也可以将主>放置在您的主机中(也可以放置在您的主机中)资源文件夹)感兴趣的配置为:
com.atomikos.icatch.max_timeout
com.atomikos.icatch.default_jta_timeout
因此,如果您配置了
transactions。属性
文件:它应该最多允许10秒钟。
请参阅:
Most of the TransactionsEssentials JTA settings can be tweaked using the
jta.properties
file (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_timeout
com.atomikos.icatch.default_jta_timeout
So if you configured your
transactions.properties
file with:It should do the trick to allow for a maximum of 10 seconds.
See: Atomikos - JtaProperties - Transaction manager