Skip to content

Commit

Permalink
Do cache.get() call before cache.computeIfAbsent(..,..)
Browse files Browse the repository at this point in the history
Resolves: quarkusio#15752
  • Loading branch information
Marcel Hanser committed May 19, 2021
1 parent 282ac10 commit 4c41c6c
Showing 1 changed file with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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<Method, Integer>() {
@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)) {
Expand Down

0 comments on commit 4c41c6c

Please sign in to comment.