diff --git a/extensions/narayana-jta/runtime/src/main/java/io/quarkus/narayana/jta/runtime/interceptor/TransactionalInterceptorBase.java b/extensions/narayana-jta/runtime/src/main/java/io/quarkus/narayana/jta/runtime/interceptor/TransactionalInterceptorBase.java index e6a009384ab032..f06bff0dda0e84 100644 --- a/extensions/narayana-jta/runtime/src/main/java/io/quarkus/narayana/jta/runtime/interceptor/TransactionalInterceptorBase.java +++ b/extensions/narayana-jta/runtime/src/main/java/io/quarkus/narayana/jta/runtime/interceptor/TransactionalInterceptorBase.java @@ -10,14 +10,11 @@ import java.util.concurrent.CompletionException; import java.util.concurrent.CompletionStage; import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Function; import javax.inject.Inject; import javax.interceptor.InvocationContext; -import javax.transaction.Status; -import javax.transaction.SystemException; -import javax.transaction.Transaction; -import javax.transaction.TransactionManager; -import javax.transaction.Transactional; +import javax.transaction.*; import org.eclipse.microprofile.config.ConfigProvider; import org.jboss.logging.Logger; @@ -111,8 +108,7 @@ protected Object invokeInOurTx(InvocationContext ic, TransactionManager tm) thro protected Object invokeInOurTx(InvocationContext ic, TransactionManager tm, RunnableWithException afterEndTransaction) throws Exception { - Integer timeoutConfiguredForMethod = cache.computeIfAbsent(ic.getMethod(), - (m) -> extractTransactionConfigurationTimeoutFromAnnotation(ic)); + Integer timeoutConfiguredForMethod = getTransactionConfigurationTimeoutFromCache(ic); int currentTmTimeout = ((CDIDelegatingTransactionManager) transactionManager).getTransactionTimeout(); @@ -177,6 +173,21 @@ protected Object invokeInOurTx(InvocationContext ic, TransactionManager tm, Runn return ret; } + private Integer getTransactionConfigurationTimeoutFromCache(InvocationContext ic) { + Integer timeoutForMethod = cache.get(ic.getMethod()); + if (Objects.nonNull(timeoutForMethod)) { + return timeoutForMethod; + } else { + return cache.computeIfAbsent(ic.getMethod(), + new Function() { + @Override + public Integer apply(Method m) { + return TransactionalInterceptorBase.this.extractTransactionConfigurationTimeoutFromAnnotation(ic); + } + }); + } + } + private Integer extractTransactionConfigurationTimeoutFromAnnotation(InvocationContext ic) { TransactionConfiguration configAnnotation = getTransactionConfiguration(ic); if (!configAnnotation.timeoutFromConfigProperty().equals(TransactionConfiguration.UNSET_TIMEOUT_CONFIG_PROPERTY)) {