Skip to content

Commit

Permalink
TransactionSynchronizationManager eagerly cleans up void ResourceHold…
Browse files Browse the repository at this point in the history
…ers on any access (SPR-8844, SPR-8845)
  • Loading branch information
jhoeller committed Nov 28, 2011
1 parent a9a068e commit c9b36fb
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ private static Object doGetResource(Object actualKey) {
// Transparently remove ResourceHolder that was marked as void...
if (value instanceof ResourceHolder && ((ResourceHolder) value).isVoid()) {
map.remove(actualKey);
// Remove entire ThreadLocal if empty...
if (map.isEmpty()) {
resources.remove();
}
value = null;
}
return value;
Expand All @@ -176,8 +180,13 @@ public static void bindResource(Object key, Object value) throws IllegalStateExc
map = new HashMap<Object, Object>();
resources.set(map);
}
if (map.put(actualKey, value) != null) {
throw new IllegalStateException("Already value [" + map.get(actualKey) + "] for key [" +
Object oldValue = map.put(actualKey, value);
// 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() + "]");
}
if (logger.isTraceEnabled()) {
Expand Down Expand Up @@ -226,6 +235,10 @@ private static Object doUnbindResource(Object actualKey) {
if (map.isEmpty()) {
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()) {
logger.trace("Removed value [" + value + "] for key [" + actualKey + "] from thread [" +
Thread.currentThread().getName() + "]");
Expand Down

0 comments on commit c9b36fb

Please sign in to comment.