【问题标题】:How to increase Atomikos default jta timeout based on the thread during Spring retrySpring重试期间如何根据线程增加Atomikos默认jta超时
【发布时间】:2020-10-21 11:33:43
【问题描述】:

我正在使用带有 Atomikos 事务的 Spring Boot 应用程序。我已在事务属性中将默认超时配置为 10000 毫秒,即 10 秒。

交易.properties

com.atomikos.icatch.default_jta_timeout=10000
com.atomikos.icatch.threaded_2pc=true
com.atomikos.icatch.max_timeout=300000
com.atomikos.icatch.max_actives=1000 

由于 Jta 超时,如果任何用户事务花费超过 10 秒,则该特定线程事务将超时并回滚。

用户事务超过指定阈值时间的 Atomikos 日志。

[Atomikos:3] [] [] [] [] c.a.icatch.imp.ActiveStateHandler - Transaction InsightJTA160327483422900028 has timed out - rolling back...

我的问题是,我正在为特定功能使用 Spring 重试。例如,如果发生任何数据库异常或 MQ 异常,那么我将对同一个函数进行 3 次重试,间隔为 30 秒,如下所示,

            retryTemplate.execute(context -> {
                log.info("Processing request...");   // Time interval 30 sec, max attempts 3  
                saveUserOperation(user);             // if any exception, current thread time out,      
                dropMessageToMQ(message);            // should be increased to 120S(120000ms) 
            });  

这里如果 saveUserOperation 或 dropMessageToMQ 抛出任何异常,则 Spring 重试将在 30 秒后开始,但这里我已配置默认 JTA 时间为 10 秒,因此在重试开始之前,事务超时。我只是想知道,当重试发生时,是否有可能增加当前线程的超时时间。

我可以增加默认超时,但它适用于所有线程,我不想这样做。

【问题讨论】:

    标签: transactions jta spring-retry atomikos


    【解决方案1】:

    在 JTA UserTransaction 对象上尝试 setTransactionTimeout

    或者使用 Spring 的 @Transactional 超时:refer

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-13
      • 1970-01-01
      • 1970-01-01
      • 2014-10-30
      • 2015-07-07
      • 1970-01-01
      • 2017-06-24
      • 1970-01-01
      相关资源
      最近更新 更多