Skip to content

Transaction-scoped resource binding in TransactionSynchronizationManager #35182

@beikov

Description

@beikov

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.

Metadata

Metadata

Assignees

Labels

in: dataIssues in data modules (jdbc, orm, oxm, tx)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions