Browse Source

Reuse NoTransactionInContextException instances

New NoTransactionInContextException instances are created frequently in
TransactionContextManager#currentContext() when there is no transaction,
we could reuse the same instance instead to reduce the GC pressure.

Closes gh-33601
pull/33604/head
Sébastien Deleuze 1 year ago
parent
commit
8e3846991d
  1. 5
      spring-tx/src/main/java/org/springframework/transaction/reactive/TransactionContextManager.java

5
spring-tx/src/main/java/org/springframework/transaction/reactive/TransactionContextManager.java

@ -37,6 +37,9 @@ import org.springframework.transaction.NoTransactionException; @@ -37,6 +37,9 @@ import org.springframework.transaction.NoTransactionException;
*/
public abstract class TransactionContextManager {
private static final NoTransactionInContextException NO_TRANSACTION_IN_CONTEXT_EXCEPTION =
new NoTransactionInContextException();
private TransactionContextManager() {
}
@ -60,7 +63,7 @@ public abstract class TransactionContextManager { @@ -60,7 +63,7 @@ public abstract class TransactionContextManager {
return Mono.just(holder.currentContext());
}
}
return Mono.error(new NoTransactionInContextException());
return Mono.error(NO_TRANSACTION_IN_CONTEXT_EXCEPTION);
});
}

Loading…
Cancel
Save