diff options
author | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-13 13:28:16 +0000 |
---|---|---|
committer | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-13 13:28:16 +0000 |
commit | 2e637af9254c4dc41963c71745e1bc7cb6c90ca6 (patch) | |
tree | 3de66f56435cd8cb920fac694896567a5807f353 /sca-java-1.x/trunk/modules/core/src/main/java/org/apache | |
parent | 2d3a1e88aeeccd0cb72be2637cae921027c44626 (diff) |
TUSCANY-3312 - correct previous fix to prevent memory leak on WeakHashMap
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835844 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-1.x/trunk/modules/core/src/main/java/org/apache')
-rw-r--r-- | sca-java-1.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/SCAProxy.java | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/sca-java-1.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/SCAProxy.java b/sca-java-1.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/SCAProxy.java index b591ccedd6..f2907638ad 100644 --- a/sca-java-1.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/SCAProxy.java +++ b/sca-java-1.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/SCAProxy.java @@ -18,6 +18,7 @@ */
package org.apache.tuscany.sca.core.invocation;
+import java.lang.ref.WeakReference;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Proxy;
@@ -33,7 +34,7 @@ public class SCAProxy extends Proxy // This is a cache containing the proxy class constructor for each business interface.
// This improves performance compared to calling Proxy.newProxyInstance()
// every time that a proxy is needed.
- private static WeakHashMap cache = new WeakHashMap<String, Object>();
+ private static WeakHashMap cache = new WeakHashMap<Class, WeakReference<Constructor>>();
public static Object newProxyInstance(ClassLoader classloader, Class aclass[], InvocationHandler invocationhandler)
throws IllegalArgumentException
@@ -42,15 +43,18 @@ public class SCAProxy extends Proxy if(invocationhandler == null)
throw new NullPointerException();
// Lookup cached constructor. aclass[0] is the reference's business interface.
- Constructor proxyCTOR;
+ Constructor proxyCTOR = null;
synchronized(cache) {
- proxyCTOR = (Constructor) cache.get(aclass[0].hashCode());
+ WeakReference<Constructor> ref = (WeakReference<Constructor>) cache.get(aclass[0]);
+ if (ref != null){
+ proxyCTOR = ref.get();
+ }
}
if(proxyCTOR == null) {
Class proxyClass = getProxyClass(classloader, aclass);
proxyCTOR = proxyClass.getConstructor(constructorParams);
synchronized(cache){
- cache.put(aclass[0].hashCode(),proxyCTOR);
+ cache.put(aclass[0],new WeakReference<Constructor>(proxyCTOR));
}
}
return proxyCTOR.newInstance(new Object[] { invocationhandler });
|