Hello Simine
Simone Giannecchini a écrit :
> I was looking yesterday at the SoftHashValueMap since I need it for
> another project. I have a question regarding the WeakCollectionCleaner.
> Is it really needed? All it seems to do is clearing the internal
> reference of our WeakReference or SoftReference but it seems to do
> nothing beyond that.
The Reference objects in WeakCollection are not directly WeakReferences, but
rather some WeakReference subclass that contains some additional data needed
for
proper working of hash map. Those references override their 'clear()' method in
order to remove the entry from the hash map in addition of clearing the
reference.
So invoking Reference.clear() do not only clears the reference. It also removes
the reference from the hash map / hash set. This is explained in
WeakCollectionCleaner class javadoc, and repeated again at lines 80-81. I will
move those comments closer to the call to 'ref.clear()'.
We could argue that overriding Reference.clear() that way is yet an other
obscure trick in my code. If the comments in the code are not suffisient for
avoiding confusion, we can change that. But it would require the addition of a
new private class and casting (so more class, more code, slightly less
performance).
> (...snip...) having a thread with priority 5 as the DEFAULT
> collection cleaner doing something that we don’t need to do it might be
> an overkill, especially if you start putting a lot of references inside
> its ReferenceQueue being them weak or soft.
The thread should spend most of its time waiting. If we look at J2SE
implementation, we can find many deamon threads with priority 9 or 10.
Application do not suffer from such high priorities because those threads are
inactive most of the time. When a thread weakup, it performs its work very
quickly and go back in sleeping state very soon. Having a high priority thread
ensure that this quick work is not delayed by long standing work (even if the
long standing work is the actual application performing the "real" work
requested by the user). This is especially important if the purpose of the
quick
work is to release resources. Sooner the resource are released, better it will
be for application performances.
It may sound like the opposite of what we want, but often the "real" work needs
to be performed in a low priority thread while "system management" tasks are
performed in a high priority thread, providing that the "system management"
tasks are very short (and not too frequent) while the "real work" is very long.
Martin
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel