Description: Change the ht member from a HashTable to a WeakHashMap.

Reason: HashTable maintains a static strong reference to threads that have
NDC's associated with them.  Unless the programmer remembers to call
NDC.remove() at some point, these threads will never be garbage collected
once they finish running.  Changing to a WeakHashMap allows the garbage
collector to free inactive threads because WeakHashMap maintains only a weak
reference.  The WeakHashMap will also clean itself up and remove keys
(threads) that have been collected.  But, it's reference will be maintained
as long as the thread is running or strong referenced by some other entity.

Change: The change is simple.  Create a WeakHashMap instead of a HashTable,
push it through the Collections.synchronizedMap() method to synchronize it
like a HashTable.  Because Map does not support Enumeration, use the
Iterator class instead.  But it is unclear to me that this will be required
any longer (lazyRemove()) because the WeakHashMap cleans itself up when the
key is gc'd (according to documentation).

Implications: The NDC would no longer be backward compatible to 1.1.X
versions.  Collections, WeakHashMap, and related classes were introduced in
version 1.2.  I don't know if there is way to write the class so that it can
support both?  At the least, we could rename this version of the class or
provide a "patch" jar to override the current implementation?

Testing: None.  I am going to write a quick test program, but I wanted to
post this to initiate discussion.  If someone can tell me how to get the
testing scripts to run, I will run them too.

-Mark
 <<NDC.patch>> 

NDC.patch

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to