-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Description
TransactionSynchronizationManager
is kind of inconsistent in how it deals with "resources".
In the code I see:
private static final ThreadLocal<Map<Object, Object>> resources =
new NamedThreadLocal<>("Transactional resources");
suggesting that these resources are bound to a transaction. Further down in the Javadoc of the various methods that handle resource bind/unbind, there is no mention about transaction though, only thread local.
I was kind of caught by surprise that resources are not cleaned up after a transaction completes or stored away and restored on suspend/resume. As the implementation is right now, this resources
ThreadLocal
is not useful i.e. I could have just used my own ThreadLocal
myself.
IMO the transaction implementations should be changed to really bind these resources to a transaction. Otherwise, there is also a potential for a memory leak when somebody binds something to this resources
, but doesn't cleanup the value in a TransactionSynchronization
which really is transaction bound.