commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robert burrell donkin <robertburrelldon...@blueyonder.co.uk>
Subject Re: logging: WeakHashtable
Date Thu, 11 Nov 2004 22:43:56 GMT

On 11 Nov 2004, at 07:40, Brian Stansberry wrote:

> Hi Robert,

hi brian

>  Had a little time to look at the WeakHashtable.  Much cleaner w/o 
> reflection!

yep :)

>  A couple things occurred to me as I looked.
>  
> 1)  The instances of Referenced are not cleared from the underlying 
> table if their underlying references are cleared.
> 2)  Passing null keys/values to put() does not result in a NPE.
>  
> I attached a patch to the WeakHashtableTest that tests for these.

very much appreciated. both tests committed.

> One thought on #1 is to make Referenced a subclass of WeakReference 
> instead of a wrapper.  You can then keep a ReferenceQueue and poll it 
> to remove cleared references from the hashtable whenever get() is 
> called.  This is similar to what WeakHashMap does.

i had a bit of a think about the best way to do this. i think the 
approach outlined would be best if this were a general implementation. 
in this case, though, the majority of calls are going to be to get with 
somewhat less going to put and very few to any others. i can't think of 
any occasions when the symantics of put and get are influenced by the 
presence of extra entries. so i've opted for code that simply purges 
entries that have lost their referants which is called at the start of 
other interrogative methods. the data returned will be more stale than 
using a reference queue but i think that liveliness for put and get 
should be improved.

i'd be grateful if people would take a look at the code and try to find 
any holes in this approach or reasons why using a ReferenceQueue might 
improve liveliness (preferably with patches)...

there is one issue that has (just) struck me. in normal use, it's 
unlikely that the stale entries will ever get purged and so it might be 
necessary to purge every 100 (or so) puts, say.

- robert

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message