Merge pull request #66 from dridi/SPR-9176
* SPR-9176: Fix scoped-proxy memory leak w/ @Resource injection
This commit is contained in:
commit
ae9549ae13
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2011 the original author or authors.
|
* Copyright 2002-2012 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -35,6 +35,7 @@ import java.util.LinkedList;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.annotation.PreDestroy;
|
import javax.annotation.PreDestroy;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
@ -509,9 +510,12 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
|
||||||
*/
|
*/
|
||||||
private class ResourceElement extends LookupElement {
|
private class ResourceElement extends LookupElement {
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
protected boolean shareable = true;
|
protected boolean shareable = true;
|
||||||
|
|
||||||
|
private volatile boolean cached = false;
|
||||||
|
|
||||||
|
private volatile Object cachedFieldValue;
|
||||||
|
|
||||||
public ResourceElement(Member member, PropertyDescriptor pd) {
|
public ResourceElement(Member member, PropertyDescriptor pd) {
|
||||||
super(member, pd);
|
super(member, pd);
|
||||||
}
|
}
|
||||||
|
@ -546,7 +550,20 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object getResourceToInject(Object target, String requestingBeanName) {
|
protected Object getResourceToInject(Object target, String requestingBeanName) {
|
||||||
return getResource(this, requestingBeanName);
|
Object value = null;
|
||||||
|
if (this.cached && this.shareable) {
|
||||||
|
value = this.cachedFieldValue;
|
||||||
|
}
|
||||||
|
synchronized (this) {
|
||||||
|
if (!this.cached) {
|
||||||
|
value = getResource(this, requestingBeanName);
|
||||||
|
if (value != null && this.shareable) {
|
||||||
|
this.cachedFieldValue = value;
|
||||||
|
this.cached = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue