Oops, forgot about what I said. I must be snoozing off while writing the
email...
>Date: Wed, 22 May 2002 09:27:56 +0800
>To: "Jakarta Commons Developers List" <commons-dev@jakarta.apache.org>
>From: John Yu <john@scioworks.com>
>Subject: Re: PATCH : org.apache.commons.collections.SoftRefHashMap
>
>A while back ago, I submitted a patch for the purge() method. See,
>
> http://www.mail-archive.com/commons-dev@jakarta.apache.org/msg05831.html
>
>It seems it didn't get it. Anyway, Juozas' approach should work better.
>Along this line, (as I mentioned this in the above post), shouldn't
>SoftRefHashMap does the purging like how java.util.WeakHashMap does? i.e.
>Use the ReferenceQueue and invoke the purge() whenever a modifier method
>is called.
>--
>John
>
>At 05:20 pm 21-05-2002 +0200, you wrote:
>
>>Hi,
>>Trust me, It is not the best way to remove dead mappings :
>>
>> /**
>> * Removes References that have had their referents garbage collected
>> */
>> public void purge() {
>> Map map = getMap();
>> Set keys = map.keySet();
>> if ( keys == null ) {
>> return;
>> }
>> for ( Iterator i = keys.iterator(); i.hasNext(); ) {
>> Object key = (Object) i.next();
>> Reference ref = (Reference) map.get( key );
>> if ( ref.get() == null ) {
>> map.remove( key );
>> }
>> }
>> }
>>It must be like this code :
>>
>> private void purge() {
>>
>> SoftRef ref = (SoftRef)queue.poll();
>>
>> while( ref != null ){
>> hashMap.remove(ref.key);
>> ref = (SoftRef)queue.poll();
>> }
>>
>>
>> }
>>
>>Private it because you never know then to call it outside the map
>>implementation, if you will create some thread to remove mappings,
>>it will dublicate
>>thread in java.lang.ref.Reference implementation and it will not do
>>things better.
>
>--
>John Yu Scioworks Technologies
>e: john@scioworks.com w: +(65) 873 5989
>w: http://www.scioworks.com m: +(65) 9782 9610
>
>Scioworks Camino - "Rapid WebApp Assembly for Struts"
--
John Yu Scioworks Technologies
e: john@scioworks.com w: +(65) 873 5989
w: http://www.scioworks.com m: +(65) 9782 9610
Scioworks Camino - "Rapid WebApp Assembly for Struts"
--
To unsubscribe, e-mail: <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>
|