TransactionSynchronizationManager eagerly cleans up void ResourceHolders on any access (SPR-8844, SPR-8845)
This commit is contained in:
parent
a9a068e678
commit
c9b36fb4e6
|
|
@ -155,6 +155,10 @@ public abstract class TransactionSynchronizationManager {
|
||||||
// Transparently remove ResourceHolder that was marked as void...
|
// Transparently remove ResourceHolder that was marked as void...
|
||||||
if (value instanceof ResourceHolder && ((ResourceHolder) value).isVoid()) {
|
if (value instanceof ResourceHolder && ((ResourceHolder) value).isVoid()) {
|
||||||
map.remove(actualKey);
|
map.remove(actualKey);
|
||||||
|
// Remove entire ThreadLocal if empty...
|
||||||
|
if (map.isEmpty()) {
|
||||||
|
resources.remove();
|
||||||
|
}
|
||||||
value = null;
|
value = null;
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
|
|
@ -176,8 +180,13 @@ public abstract class TransactionSynchronizationManager {
|
||||||
map = new HashMap<Object, Object>();
|
map = new HashMap<Object, Object>();
|
||||||
resources.set(map);
|
resources.set(map);
|
||||||
}
|
}
|
||||||
if (map.put(actualKey, value) != null) {
|
Object oldValue = map.put(actualKey, value);
|
||||||
throw new IllegalStateException("Already value [" + map.get(actualKey) + "] for key [" +
|
// Transparently suppress a ResourceHolder that was marked as void...
|
||||||
|
if (oldValue instanceof ResourceHolder && ((ResourceHolder) oldValue).isVoid()) {
|
||||||
|
oldValue = null;
|
||||||
|
}
|
||||||
|
if (oldValue != null) {
|
||||||
|
throw new IllegalStateException("Already value [" + oldValue + "] for key [" +
|
||||||
actualKey + "] bound to thread [" + Thread.currentThread().getName() + "]");
|
actualKey + "] bound to thread [" + Thread.currentThread().getName() + "]");
|
||||||
}
|
}
|
||||||
if (logger.isTraceEnabled()) {
|
if (logger.isTraceEnabled()) {
|
||||||
|
|
@ -226,6 +235,10 @@ public abstract class TransactionSynchronizationManager {
|
||||||
if (map.isEmpty()) {
|
if (map.isEmpty()) {
|
||||||
resources.remove();
|
resources.remove();
|
||||||
}
|
}
|
||||||
|
// Transparently suppress a ResourceHolder that was marked as void...
|
||||||
|
if (value instanceof ResourceHolder && ((ResourceHolder) value).isVoid()) {
|
||||||
|
value = null;
|
||||||
|
}
|
||||||
if (value != null && logger.isTraceEnabled()) {
|
if (value != null && logger.isTraceEnabled()) {
|
||||||
logger.trace("Removed value [" + value + "] for key [" + actualKey + "] from thread [" +
|
logger.trace("Removed value [" + value + "] for key [" + actualKey + "] from thread [" +
|
||||||
Thread.currentThread().getName() + "]");
|
Thread.currentThread().getName() + "]");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue