Index: NDC.java
===================================================================
RCS file: /home/cvspublic/jakarta-log4j/src/java/org/apache/log4j/NDC.java,v
retrieving revision 1.11
diff -u -r1.11 NDC.java
--- NDC.java	2001/07/18 06:03:15	1.11
+++ NDC.java	2001/08/31 17:59:44
@@ -8,9 +8,11 @@
 
 package org.apache.log4j;
 
-import java.util.Hashtable;
+import java.util.Collections;
+import java.util.Map;
+import java.util.WeakHashMap;
+import java.util.Iterator;
 import java.util.Stack;
-import java.util.Enumeration;
 import java.util.Vector;
 
 import org.apache.log4j.helpers.LogLog;
@@ -92,14 +94,15 @@
   // The synchronized keyword is not used in this class. This may seem
   // dangerous, especially since the class will be used by
   // multiple-threads. In particular, all threads share the same
-  // hashtable (the "ht" variable). This is OK since java hashtables
-  // are thread safe. Same goes for Stacks.
+  // WeakHashMap (the "ht" variable). This is OK since we use the
+  // Collections.synchronizedMap method to synchronize the Map methods
+  // and make it thread safe. Stacks are inherently thread safe.
 
   // More importantly, when inheriting diagnostic contexts the child
   // thread is handed a clone of the parent's NDC.  It follows that
   // each thread has its own NDC (i.e. stack).
 
-  static Hashtable ht = new Hashtable();
+  static Map ht = Collections.synchronizedMap(new WeakHashMap());
 
   static int pushCounter = 0; // the number of times push has been called
                               // after the latest call to lazyRemove
@@ -236,13 +239,13 @@
 
       int misses = 0;
       v = new Vector(); 
-      Enumeration enum = ht.keys();
+      Iterator iter = ht.keySet().iterator();
       // We give up after 4 straigt missses. That is 4 consecutive
       // inspected threads in 'ht' that turn out to be alive.
       // The higher the proportion on dead threads in ht, the higher the
       // chances of removal.
-      while(enum.hasMoreElements() && (misses <= 4)) {
-	Thread t = (Thread) enum.nextElement();
+      while(iter.hasNext() && (misses <= 4)) {
+	Thread t = (Thread) iter.next();
 	if(t.isAlive()) {
 	  misses++;
 	} else {

