You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by ra...@apache.org on 2004/12/24 11:46:24 UTC
cvs commit: xml-security/src/org/apache/xml/security/utils CachedXPathAPIHolder.java
raul 2004/12/24 02:46:24
Modified: src/org/apache/xml/security/utils CachedXPathAPIHolder.java
Log:
Trying to fix a pseudo-leak when using too much threads.
Revision Changes Path
1.2 +12 -4 xml-security/src/org/apache/xml/security/utils/CachedXPathAPIHolder.java
Index: CachedXPathAPIHolder.java
===================================================================
RCS file: /home/cvs/xml-security/src/org/apache/xml/security/utils/CachedXPathAPIHolder.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CachedXPathAPIHolder.java 3 Aug 2004 18:01:21 -0000 1.1
+++ CachedXPathAPIHolder.java 24 Dec 2004 10:46:24 -0000 1.2
@@ -16,6 +16,10 @@
*/
package org.apache.xml.security.utils;
+import java.lang.ref.SoftReference;
+import java.lang.ref.WeakReference;
+import java.util.WeakHashMap;
+
import org.apache.xpath.CachedXPathAPI;
@@ -23,7 +27,8 @@
* @author Raul Benito
*/
public class CachedXPathAPIHolder {
- static ThreadLocal local=new ThreadLocal();
+ //static ThreadLocal local=new ThreadLocal();
+ static WeakHashMap local=new WeakHashMap();
CachedXPathAPI cx;
/**
@@ -38,11 +43,14 @@
*/
public CachedXPathAPI getCachedXPathAPI() {
if (cx==null) {
- cx=(CachedXPathAPI)local.get();
+ SoftReference sr=(SoftReference)local.get(Thread.currentThread());
+ if (sr!=null) {
+ cx=(CachedXPathAPI)sr.get();
+ }
if (cx==null) {
cx=new CachedXPathAPI();
- local.set(cx);
- }
+ local.put(Thread.currentThread(),new SoftReference(cx));
+ }
//cx.getXPathContext().reset();//
//cx=new CachedXPathAPI();
}