簡體   English   中英

Spring重試時如何根據線程增加Atomikos默認jta超時時間

[英]How to increase Atomikos default jta timeout based on the thread during Spring retry

我正在使用帶有 Atomikos 事務的 Spring 啟動應用程序。 我已將默認超時配置為 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 異常,那么我將以 30 秒的間隔對同一個函數進行 3 次重試,如下所示,

            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 秒,因此在重試開始之前,事務超時。 我只想知道,是否有可能在重試發生時增加當前線程的超時時間。

我可以增加默認超時,但它適用於所有線程,我不想這樣做。

在 JTA UserTransaction對象上嘗試setTransactionTimeout

或者使用帶有超時的 Spring 的@Transactionalrefer

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM