Skip to content

Commit

Permalink
Reuse NoTransactionInContextException instances
Browse files Browse the repository at this point in the history
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 spring-projectsgh-33601
  • Loading branch information
sdeleuze committed Sep 27, 2024
1 parent bed3025 commit 8e38469
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
*/
public abstract class TransactionContextManager {

private static final NoTransactionInContextException NO_TRANSACTION_IN_CONTEXT_EXCEPTION =
new NoTransactionInContextException();

private TransactionContextManager() {
}

Expand All @@ -60,7 +63,7 @@ public static Mono<TransactionContext> currentContext() {
return Mono.just(holder.currentContext());
}
}
return Mono.error(new NoTransactionInContextException());
return Mono.error(NO_TRANSACTION_IN_CONTEXT_EXCEPTION);
});
}

Expand Down

0 comments on commit 8e38469

Please sign in to comment.