Skip to content

Commit 8e38469

Browse files
committed
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
1 parent bed3025 commit 8e38469

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
*/
3838
public abstract class TransactionContextManager {
3939

40+
private static final NoTransactionInContextException NO_TRANSACTION_IN_CONTEXT_EXCEPTION =
41+
new NoTransactionInContextException();
42+
4043
private TransactionContextManager() {
4144
}
4245

@@ -60,7 +63,7 @@ public static Mono<TransactionContext> currentContext() {
6063
return Mono.just(holder.currentContext());
6164
}
6265
}
63-
return Mono.error(new NoTransactionInContextException());
66+
return Mono.error(NO_TRANSACTION_IN_CONTEXT_EXCEPTION);
6467
});
6568
}
6669

0 commit comments

Comments
 (0)