使用Atomikos减少JTA的交易超时

发布于 2025-02-09 19:53:29 字数 1025 浏览 1 评论 0原文

我正在尝试使用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
})

我如何测试此问题:

  1. 通过SQLDEVEVELER锁定一行,
  2. 尝试通过应用程序更新同一行,
  3. 不断等待锁,
  4. 最终会出来。

我希望根据上述设置在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:

  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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半夏半凉 2025-02-16 19:53:29

可以使用jta.properties file(放置在classPath的根部)或transactions.properties(也可以将主>放置在您的主机中(也可以放置在您的主机中)资源文件夹)

感兴趣的配置为:

属性名称描述,因为
com.atomikos.icatch.max_timeout指定可以进行交易的最大超时(以毫秒为单位)。默认为300000。这意味着调用userTransaction.setTransactionTimeOut(),其值高于此处配置的值将最大为此值。对于4.x或更高的值,值为0表示最大值(即允许无限的超时)。注意:截至5.0,使用0个干扰恢复。而是使用long.max_value指定无限。3.x,4.x
com.atomikos.icatch.default_jta_timeoutJTA Transactions的默认超时(可选,默认为10000 ms)3.4,4.x,

因此,如果您配置了transactions。属性文件:

# 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

它应该最多允许10秒钟。

请参阅:

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 nameDescriptionSince
com.atomikos.icatch.max_timeoutSpecifies 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_timeoutThe 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文