logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From grobme...@apache.org
Subject svn commit: r1232645 - /logging/log4j/trunk/src/main/java/org/apache/log4j/MDC.java
Date Tue, 17 Jan 2012 23:23:07 GMT
Author: grobmeier
Date: Tue Jan 17 23:23:06 2012
New Revision: 1232645

URL: http://svn.apache.org/viewvc?rev=1232645&view=rev
Log:
made fix jdk 1.3 compatible

Modified:
    logging/log4j/trunk/src/main/java/org/apache/log4j/MDC.java

Modified: logging/log4j/trunk/src/main/java/org/apache/log4j/MDC.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/main/java/org/apache/log4j/MDC.java?rev=1232645&r1=1232644&r2=1232645&view=diff
==============================================================================
--- logging/log4j/trunk/src/main/java/org/apache/log4j/MDC.java (original)
+++ logging/log4j/trunk/src/main/java/org/apache/log4j/MDC.java Tue Jan 17 23:23:06 2012
@@ -17,6 +17,8 @@
 
 package org.apache.log4j;
 
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.util.Hashtable;
 import org.apache.log4j.helpers.Loader;
 import org.apache.log4j.helpers.ThreadLocalMap;
@@ -49,13 +51,21 @@ public class MDC {
   boolean java1;
   
   Object tlm;
-  
+
+  private Method removeMethod;
+    
   private
   MDC() {
     java1 = Loader.isJava1();
     if(!java1) {
       tlm = new ThreadLocalMap();
     }
+
+    try {
+      removeMethod = ThreadLocal.class.getMethod("remove", null);
+    } catch (NoSuchMethodException e) {
+      // don't do anything - java prior 1.5
+    }
   }
 
   /**
@@ -181,7 +191,16 @@ public class MDC {
       if(ht != null) {
         ht.clear();
       }
-      ((ThreadLocalMap)tlm).remove();
+      if(removeMethod != null) {
+          // java 1.3/1.4 does not have remove - will suffer from a memory leak
+          try {
+            removeMethod.invoke(tlm, null);
+          } catch (IllegalAccessException e) {
+            // should not happen
+          } catch (InvocationTargetException e) {
+            // should not happen
+          }
+      }
     }
   }
 



Mime
View raw message